]>
Commit | Line | Data |
---|---|---|
d7e09d03 PT |
1 | /* |
2 | * GPL HEADER START | |
3 | * | |
4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 only, | |
8 | * as published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * General Public License version 2 for more details (a copy is included | |
14 | * in the LICENSE file that accompanied this code). | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * version 2 along with this program; If not, see | |
18 | * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf | |
19 | * | |
20 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
21 | * CA 95054 USA or visit www.sun.com if you need additional information or | |
22 | * have any questions. | |
23 | * | |
24 | * GPL HEADER END | |
25 | */ | |
26 | /* | |
27 | * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. | |
28 | * Use is subject to license terms. | |
29 | * | |
30 | * Copyright (c) 2011, 2012, Intel Corporation. | |
31 | */ | |
32 | /* | |
33 | * This file is part of Lustre, http://www.lustre.org/ | |
34 | * Lustre is a trademark of Sun Microsystems, Inc. | |
35 | * | |
36 | * lustre/ptlrpc/recover.c | |
37 | * | |
38 | * Author: Mike Shaver <shaver@clusterfs.com> | |
39 | */ | |
40 | ||
41 | #define DEBUG_SUBSYSTEM S_RPC | |
9fdaf8c0 | 42 | #include "../../include/linux/libcfs/libcfs.h" |
d7e09d03 PT |
43 | |
44 | #include <obd_support.h> | |
45 | #include <lustre_ha.h> | |
46 | #include <lustre_net.h> | |
47 | #include <lustre_import.h> | |
48 | #include <lustre_export.h> | |
49 | #include <obd.h> | |
50 | #include <obd_ost.h> | |
51 | #include <obd_class.h> | |
d7e09d03 PT |
52 | #include <linux/list.h> |
53 | ||
54 | #include "ptlrpc_internal.h" | |
55 | ||
56 | /** | |
57 | * Start recovery on disconnected import. | |
58 | * This is done by just attempting a connect | |
59 | */ | |
60 | void ptlrpc_initiate_recovery(struct obd_import *imp) | |
61 | { | |
d7e09d03 PT |
62 | CDEBUG(D_HA, "%s: starting recovery\n", obd2cli_tgt(imp->imp_obd)); |
63 | ptlrpc_connect_import(imp); | |
d7e09d03 PT |
64 | } |
65 | ||
66 | /** | |
67 | * Identify what request from replay list needs to be replayed next | |
68 | * (based on what we have already replayed) and send it to server. | |
69 | */ | |
70 | int ptlrpc_replay_next(struct obd_import *imp, int *inflight) | |
71 | { | |
72 | int rc = 0; | |
73 | struct list_head *tmp, *pos; | |
74 | struct ptlrpc_request *req = NULL; | |
75 | __u64 last_transno; | |
d7e09d03 PT |
76 | |
77 | *inflight = 0; | |
78 | ||
79 | /* It might have committed some after we last spoke, so make sure we | |
80 | * get rid of them now. | |
81 | */ | |
82 | spin_lock(&imp->imp_lock); | |
83 | imp->imp_last_transno_checked = 0; | |
84 | ptlrpc_free_committed(imp); | |
85 | last_transno = imp->imp_last_replay_transno; | |
86 | spin_unlock(&imp->imp_lock); | |
87 | ||
88 | CDEBUG(D_HA, "import %p from %s committed "LPU64" last "LPU64"\n", | |
89 | imp, obd2cli_tgt(imp->imp_obd), | |
90 | imp->imp_peer_committed_transno, last_transno); | |
91 | ||
92 | /* Do I need to hold a lock across this iteration? We shouldn't be | |
93 | * racing with any additions to the list, because we're in recovery | |
94 | * and are therefore not processing additional requests to add. Calls | |
95 | * to ptlrpc_free_committed might commit requests, but nothing "newer" | |
96 | * than the one we're replaying (it can't be committed until it's | |
97 | * replayed, and we're doing that here). l_f_e_safe protects against | |
98 | * problems with the current request being committed, in the unlikely | |
99 | * event of that race. So, in conclusion, I think that it's safe to | |
100 | * perform this list-walk without the imp_lock held. | |
101 | * | |
102 | * But, the {mdc,osc}_replay_open callbacks both iterate | |
103 | * request lists, and have comments saying they assume the | |
104 | * imp_lock is being held by ptlrpc_replay, but it's not. it's | |
105 | * just a little race... | |
106 | */ | |
63d42578 HZ |
107 | |
108 | /* Replay all the committed open requests on committed_list first */ | |
109 | if (!list_empty(&imp->imp_committed_list)) { | |
110 | tmp = imp->imp_committed_list.prev; | |
d7e09d03 PT |
111 | req = list_entry(tmp, struct ptlrpc_request, |
112 | rq_replay_list); | |
113 | ||
63d42578 | 114 | /* The last request on committed_list hasn't been replayed */ |
d7e09d03 | 115 | if (req->rq_transno > last_transno) { |
63d42578 HZ |
116 | /* Since the imp_committed_list is immutable before |
117 | * all of it's requests being replayed, it's safe to | |
118 | * use a cursor to accelerate the search */ | |
119 | imp->imp_replay_cursor = imp->imp_replay_cursor->next; | |
120 | ||
121 | while (imp->imp_replay_cursor != | |
122 | &imp->imp_committed_list) { | |
123 | req = list_entry(imp->imp_replay_cursor, | |
124 | struct ptlrpc_request, | |
125 | rq_replay_list); | |
126 | if (req->rq_transno > last_transno) | |
127 | break; | |
128 | ||
129 | req = NULL; | |
130 | imp->imp_replay_cursor = | |
131 | imp->imp_replay_cursor->next; | |
132 | } | |
133 | } else { | |
134 | /* All requests on committed_list have been replayed */ | |
135 | imp->imp_replay_cursor = &imp->imp_committed_list; | |
136 | req = NULL; | |
137 | } | |
138 | } | |
139 | ||
140 | /* All the requests in committed list have been replayed, let's replay | |
141 | * the imp_replay_list */ | |
142 | if (req == NULL) { | |
143 | list_for_each_safe(tmp, pos, &imp->imp_replay_list) { | |
144 | req = list_entry(tmp, struct ptlrpc_request, | |
145 | rq_replay_list); | |
146 | ||
147 | if (req->rq_transno > last_transno) | |
148 | break; | |
149 | req = NULL; | |
d7e09d03 | 150 | } |
d7e09d03 PT |
151 | } |
152 | ||
63d42578 HZ |
153 | /* If need to resend the last sent transno (because a reconnect |
154 | * has occurred), then stop on the matching req and send it again. | |
155 | * If, however, the last sent transno has been committed then we | |
156 | * continue replay from the next request. */ | |
157 | if (req != NULL && imp->imp_resend_replay) | |
158 | lustre_msg_add_flags(req->rq_reqmsg, MSG_RESENT); | |
159 | ||
d7e09d03 PT |
160 | spin_lock(&imp->imp_lock); |
161 | imp->imp_resend_replay = 0; | |
162 | spin_unlock(&imp->imp_lock); | |
163 | ||
164 | if (req != NULL) { | |
165 | rc = ptlrpc_replay_req(req); | |
166 | if (rc) { | |
167 | CERROR("recovery replay error %d for req " | |
168 | LPU64"\n", rc, req->rq_xid); | |
0a3bdb00 | 169 | return rc; |
d7e09d03 PT |
170 | } |
171 | *inflight = 1; | |
172 | } | |
0a3bdb00 | 173 | return rc; |
d7e09d03 PT |
174 | } |
175 | ||
176 | /** | |
177 | * Schedule resending of request on sending_list. This is done after | |
178 | * we completed replaying of requests and locks. | |
179 | */ | |
180 | int ptlrpc_resend(struct obd_import *imp) | |
181 | { | |
182 | struct ptlrpc_request *req, *next; | |
183 | ||
d7e09d03 PT |
184 | /* As long as we're in recovery, nothing should be added to the sending |
185 | * list, so we don't need to hold the lock during this iteration and | |
186 | * resend process. | |
187 | */ | |
188 | /* Well... what if lctl recover is called twice at the same time? | |
189 | */ | |
190 | spin_lock(&imp->imp_lock); | |
191 | if (imp->imp_state != LUSTRE_IMP_RECOVER) { | |
192 | spin_unlock(&imp->imp_lock); | |
0a3bdb00 | 193 | return -1; |
d7e09d03 PT |
194 | } |
195 | ||
196 | list_for_each_entry_safe(req, next, &imp->imp_sending_list, | |
197 | rq_list) { | |
198 | LASSERTF((long)req > PAGE_CACHE_SIZE && req != LP_POISON, | |
199 | "req %p bad\n", req); | |
200 | LASSERTF(req->rq_type != LI_POISON, "req %p freed\n", req); | |
201 | if (!ptlrpc_no_resend(req)) | |
202 | ptlrpc_resend_req(req); | |
203 | } | |
204 | spin_unlock(&imp->imp_lock); | |
205 | ||
0a3bdb00 | 206 | return 0; |
d7e09d03 PT |
207 | } |
208 | EXPORT_SYMBOL(ptlrpc_resend); | |
209 | ||
210 | /** | |
211 | * Go through all requests in delayed list and wake their threads | |
212 | * for resending | |
213 | */ | |
214 | void ptlrpc_wake_delayed(struct obd_import *imp) | |
215 | { | |
216 | struct list_head *tmp, *pos; | |
217 | struct ptlrpc_request *req; | |
218 | ||
219 | spin_lock(&imp->imp_lock); | |
220 | list_for_each_safe(tmp, pos, &imp->imp_delayed_list) { | |
221 | req = list_entry(tmp, struct ptlrpc_request, rq_list); | |
222 | ||
223 | DEBUG_REQ(D_HA, req, "waking (set %p):", req->rq_set); | |
224 | ptlrpc_client_wake_req(req); | |
225 | } | |
226 | spin_unlock(&imp->imp_lock); | |
227 | } | |
228 | EXPORT_SYMBOL(ptlrpc_wake_delayed); | |
229 | ||
230 | void ptlrpc_request_handle_notconn(struct ptlrpc_request *failed_req) | |
231 | { | |
232 | struct obd_import *imp = failed_req->rq_import; | |
d7e09d03 PT |
233 | |
234 | CDEBUG(D_HA, "import %s of %s@%s abruptly disconnected: reconnecting\n", | |
235 | imp->imp_obd->obd_name, obd2cli_tgt(imp->imp_obd), | |
236 | imp->imp_connection->c_remote_uuid.uuid); | |
237 | ||
238 | if (ptlrpc_set_import_discon(imp, | |
239 | lustre_msg_get_conn_cnt(failed_req->rq_reqmsg))) { | |
240 | if (!imp->imp_replayable) { | |
241 | CDEBUG(D_HA, "import %s@%s for %s not replayable, " | |
242 | "auto-deactivating\n", | |
243 | obd2cli_tgt(imp->imp_obd), | |
244 | imp->imp_connection->c_remote_uuid.uuid, | |
245 | imp->imp_obd->obd_name); | |
246 | ptlrpc_deactivate_import(imp); | |
247 | } | |
248 | /* to control recovery via lctl {disable|enable}_recovery */ | |
249 | if (imp->imp_deactive == 0) | |
250 | ptlrpc_connect_import(imp); | |
251 | } | |
252 | ||
253 | /* Wait for recovery to complete and resend. If evicted, then | |
254 | this request will be errored out later.*/ | |
255 | spin_lock(&failed_req->rq_lock); | |
256 | if (!failed_req->rq_no_resend) | |
257 | failed_req->rq_resend = 1; | |
258 | spin_unlock(&failed_req->rq_lock); | |
d7e09d03 PT |
259 | } |
260 | ||
261 | /** | |
262 | * Administratively active/deactive a client. | |
263 | * This should only be called by the ioctl interface, currently | |
264 | * - the lctl deactivate and activate commands | |
265 | * - echo 0/1 >> /proc/osc/XXX/active | |
266 | * - client umount -f (ll_umount_begin) | |
267 | */ | |
268 | int ptlrpc_set_import_active(struct obd_import *imp, int active) | |
269 | { | |
270 | struct obd_device *obd = imp->imp_obd; | |
271 | int rc = 0; | |
272 | ||
d7e09d03 PT |
273 | LASSERT(obd); |
274 | ||
275 | /* When deactivating, mark import invalid, and abort in-flight | |
276 | * requests. */ | |
277 | if (!active) { | |
278 | LCONSOLE_WARN("setting import %s INACTIVE by administrator " | |
279 | "request\n", obd2cli_tgt(imp->imp_obd)); | |
280 | ||
281 | /* set before invalidate to avoid messages about imp_inval | |
282 | * set without imp_deactive in ptlrpc_import_delay_req */ | |
283 | spin_lock(&imp->imp_lock); | |
284 | imp->imp_deactive = 1; | |
285 | spin_unlock(&imp->imp_lock); | |
286 | ||
287 | obd_import_event(imp->imp_obd, imp, IMP_EVENT_DEACTIVATE); | |
288 | ||
289 | ptlrpc_invalidate_import(imp); | |
290 | } | |
291 | ||
292 | /* When activating, mark import valid, and attempt recovery */ | |
293 | if (active) { | |
294 | CDEBUG(D_HA, "setting import %s VALID\n", | |
295 | obd2cli_tgt(imp->imp_obd)); | |
296 | ||
297 | spin_lock(&imp->imp_lock); | |
298 | imp->imp_deactive = 0; | |
299 | spin_unlock(&imp->imp_lock); | |
300 | obd_import_event(imp->imp_obd, imp, IMP_EVENT_ACTIVATE); | |
301 | ||
302 | rc = ptlrpc_recover_import(imp, NULL, 0); | |
303 | } | |
304 | ||
0a3bdb00 | 305 | return rc; |
d7e09d03 PT |
306 | } |
307 | EXPORT_SYMBOL(ptlrpc_set_import_active); | |
308 | ||
309 | /* Attempt to reconnect an import */ | |
310 | int ptlrpc_recover_import(struct obd_import *imp, char *new_uuid, int async) | |
311 | { | |
312 | int rc = 0; | |
d7e09d03 PT |
313 | |
314 | spin_lock(&imp->imp_lock); | |
315 | if (imp->imp_state == LUSTRE_IMP_NEW || imp->imp_deactive || | |
316 | atomic_read(&imp->imp_inval_count)) | |
317 | rc = -EINVAL; | |
318 | spin_unlock(&imp->imp_lock); | |
319 | if (rc) | |
320 | GOTO(out, rc); | |
321 | ||
322 | /* force import to be disconnected. */ | |
323 | ptlrpc_set_import_discon(imp, 0); | |
324 | ||
325 | if (new_uuid) { | |
326 | struct obd_uuid uuid; | |
327 | ||
328 | /* intruct import to use new uuid */ | |
329 | obd_str2uuid(&uuid, new_uuid); | |
330 | rc = import_set_conn_priority(imp, &uuid); | |
331 | if (rc) | |
332 | GOTO(out, rc); | |
333 | } | |
334 | ||
335 | /* Check if reconnect is already in progress */ | |
336 | spin_lock(&imp->imp_lock); | |
337 | if (imp->imp_state != LUSTRE_IMP_DISCON) { | |
338 | imp->imp_force_verify = 1; | |
339 | rc = -EALREADY; | |
340 | } | |
341 | spin_unlock(&imp->imp_lock); | |
342 | if (rc) | |
343 | GOTO(out, rc); | |
344 | ||
345 | rc = ptlrpc_connect_import(imp); | |
346 | if (rc) | |
347 | GOTO(out, rc); | |
348 | ||
349 | if (!async) { | |
350 | struct l_wait_info lwi; | |
351 | int secs = cfs_time_seconds(obd_timeout); | |
352 | ||
353 | CDEBUG(D_HA, "%s: recovery started, waiting %u seconds\n", | |
354 | obd2cli_tgt(imp->imp_obd), secs); | |
355 | ||
356 | lwi = LWI_TIMEOUT(secs, NULL, NULL); | |
357 | rc = l_wait_event(imp->imp_recovery_waitq, | |
358 | !ptlrpc_import_in_recovery(imp), &lwi); | |
359 | CDEBUG(D_HA, "%s: recovery finished\n", | |
360 | obd2cli_tgt(imp->imp_obd)); | |
361 | } | |
d7e09d03 PT |
362 | |
363 | out: | |
364 | return rc; | |
365 | } | |
366 | EXPORT_SYMBOL(ptlrpc_recover_import); | |
367 | ||
368 | int ptlrpc_import_in_recovery(struct obd_import *imp) | |
369 | { | |
370 | int in_recovery = 1; | |
88291a7a | 371 | |
d7e09d03 PT |
372 | spin_lock(&imp->imp_lock); |
373 | if (imp->imp_state == LUSTRE_IMP_FULL || | |
374 | imp->imp_state == LUSTRE_IMP_CLOSED || | |
88291a7a AD |
375 | imp->imp_state == LUSTRE_IMP_DISCON || |
376 | imp->imp_obd->obd_no_recov) | |
d7e09d03 PT |
377 | in_recovery = 0; |
378 | spin_unlock(&imp->imp_lock); | |
88291a7a | 379 | |
d7e09d03 PT |
380 | return in_recovery; |
381 | } |