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) 2003, 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/import.c | |
37 | * | |
38 | * Author: Mike Shaver <shaver@clusterfs.com> | |
39 | */ | |
40 | ||
41 | #define DEBUG_SUBSYSTEM S_RPC | |
42 | ||
43 | #include <obd_support.h> | |
44 | #include <lustre_ha.h> | |
45 | #include <lustre_net.h> | |
46 | #include <lustre_import.h> | |
47 | #include <lustre_export.h> | |
48 | #include <obd.h> | |
49 | #include <obd_cksum.h> | |
50 | #include <obd_class.h> | |
51 | ||
52 | #include "ptlrpc_internal.h" | |
53 | ||
54 | struct ptlrpc_connect_async_args { | |
55 | __u64 pcaa_peer_committed; | |
56 | int pcaa_initial_connect; | |
57 | }; | |
58 | ||
59 | /** | |
60 | * Updates import \a imp current state to provided \a state value | |
61 | * Helper function. Must be called under imp_lock. | |
62 | */ | |
63 | static void __import_set_state(struct obd_import *imp, | |
64 | enum lustre_imp_state state) | |
65 | { | |
66 | imp->imp_state = state; | |
67 | imp->imp_state_hist[imp->imp_state_hist_idx].ish_state = state; | |
68 | imp->imp_state_hist[imp->imp_state_hist_idx].ish_time = | |
69 | cfs_time_current_sec(); | |
70 | imp->imp_state_hist_idx = (imp->imp_state_hist_idx + 1) % | |
71 | IMP_STATE_HIST_LEN; | |
72 | } | |
73 | ||
74 | /* A CLOSED import should remain so. */ | |
532118c0 KM |
75 | #define IMPORT_SET_STATE_NOLOCK(imp, state) \ |
76 | do { \ | |
77 | if (imp->imp_state != LUSTRE_IMP_CLOSED) { \ | |
78 | CDEBUG(D_HA, "%p %s: changing import state from %s to %s\n", \ | |
79 | imp, obd2cli_tgt(imp->imp_obd), \ | |
80 | ptlrpc_import_state_name(imp->imp_state), \ | |
81 | ptlrpc_import_state_name(state)); \ | |
82 | __import_set_state(imp, state); \ | |
83 | } \ | |
3949015e | 84 | } while (0) |
d7e09d03 PT |
85 | |
86 | #define IMPORT_SET_STATE(imp, state) \ | |
87 | do { \ | |
88 | spin_lock(&imp->imp_lock); \ | |
89 | IMPORT_SET_STATE_NOLOCK(imp, state); \ | |
90 | spin_unlock(&imp->imp_lock); \ | |
3949015e | 91 | } while (0) |
d7e09d03 PT |
92 | |
93 | ||
94 | static int ptlrpc_connect_interpret(const struct lu_env *env, | |
95 | struct ptlrpc_request *request, | |
96 | void * data, int rc); | |
97 | int ptlrpc_import_recovery_state_machine(struct obd_import *imp); | |
98 | ||
99 | /* Only this function is allowed to change the import state when it is | |
100 | * CLOSED. I would rather refcount the import and free it after | |
101 | * disconnection like we do with exports. To do that, the client_obd | |
102 | * will need to save the peer info somewhere other than in the import, | |
103 | * though. */ | |
104 | int ptlrpc_init_import(struct obd_import *imp) | |
105 | { | |
106 | spin_lock(&imp->imp_lock); | |
107 | ||
108 | imp->imp_generation++; | |
109 | imp->imp_state = LUSTRE_IMP_NEW; | |
110 | ||
111 | spin_unlock(&imp->imp_lock); | |
112 | ||
113 | return 0; | |
114 | } | |
115 | EXPORT_SYMBOL(ptlrpc_init_import); | |
116 | ||
117 | #define UUID_STR "_UUID" | |
118 | void deuuidify(char *uuid, const char *prefix, char **uuid_start, int *uuid_len) | |
119 | { | |
120 | *uuid_start = !prefix || strncmp(uuid, prefix, strlen(prefix)) | |
121 | ? uuid : uuid + strlen(prefix); | |
122 | ||
123 | *uuid_len = strlen(*uuid_start); | |
124 | ||
125 | if (*uuid_len < strlen(UUID_STR)) | |
126 | return; | |
127 | ||
128 | if (!strncmp(*uuid_start + *uuid_len - strlen(UUID_STR), | |
129 | UUID_STR, strlen(UUID_STR))) | |
130 | *uuid_len -= strlen(UUID_STR); | |
131 | } | |
132 | EXPORT_SYMBOL(deuuidify); | |
133 | ||
134 | /** | |
135 | * Returns true if import was FULL, false if import was already not | |
136 | * connected. | |
137 | * @imp - import to be disconnected | |
138 | * @conn_cnt - connection count (epoch) of the request that timed out | |
139 | * and caused the disconnection. In some cases, multiple | |
140 | * inflight requests can fail to a single target (e.g. OST | |
141 | * bulk requests) and if one has already caused a reconnection | |
142 | * (increasing the import->conn_cnt) the older failure should | |
143 | * not also cause a reconnection. If zero it forces a reconnect. | |
144 | */ | |
145 | int ptlrpc_set_import_discon(struct obd_import *imp, __u32 conn_cnt) | |
146 | { | |
147 | int rc = 0; | |
148 | ||
149 | spin_lock(&imp->imp_lock); | |
150 | ||
151 | if (imp->imp_state == LUSTRE_IMP_FULL && | |
152 | (conn_cnt == 0 || conn_cnt == imp->imp_conn_cnt)) { | |
153 | char *target_start; | |
154 | int target_len; | |
155 | ||
156 | deuuidify(obd2cli_tgt(imp->imp_obd), NULL, | |
157 | &target_start, &target_len); | |
158 | ||
159 | if (imp->imp_replayable) { | |
160 | LCONSOLE_WARN("%s: Connection to %.*s (at %s) was " | |
161 | "lost; in progress operations using this " | |
162 | "service will wait for recovery to complete\n", | |
163 | imp->imp_obd->obd_name, target_len, target_start, | |
164 | libcfs_nid2str(imp->imp_connection->c_peer.nid)); | |
165 | } else { | |
166 | LCONSOLE_ERROR_MSG(0x166, "%s: Connection to " | |
167 | "%.*s (at %s) was lost; in progress " | |
168 | "operations using this service will fail\n", | |
169 | imp->imp_obd->obd_name, | |
170 | target_len, target_start, | |
171 | libcfs_nid2str(imp->imp_connection->c_peer.nid)); | |
172 | } | |
d7e09d03 PT |
173 | IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_DISCON); |
174 | spin_unlock(&imp->imp_lock); | |
175 | ||
176 | if (obd_dump_on_timeout) | |
177 | libcfs_debug_dumplog(); | |
178 | ||
179 | obd_import_event(imp->imp_obd, imp, IMP_EVENT_DISCON); | |
180 | rc = 1; | |
181 | } else { | |
182 | spin_unlock(&imp->imp_lock); | |
183 | CDEBUG(D_HA, "%s: import %p already %s (conn %u, was %u): %s\n", | |
184 | imp->imp_client->cli_name, imp, | |
185 | (imp->imp_state == LUSTRE_IMP_FULL && | |
186 | imp->imp_conn_cnt > conn_cnt) ? | |
187 | "reconnected" : "not connected", imp->imp_conn_cnt, | |
188 | conn_cnt, ptlrpc_import_state_name(imp->imp_state)); | |
189 | } | |
190 | ||
191 | return rc; | |
192 | } | |
193 | ||
194 | /* Must be called with imp_lock held! */ | |
195 | static void ptlrpc_deactivate_and_unlock_import(struct obd_import *imp) | |
196 | { | |
d7e09d03 PT |
197 | LASSERT(spin_is_locked(&imp->imp_lock)); |
198 | ||
199 | CDEBUG(D_HA, "setting import %s INVALID\n", obd2cli_tgt(imp->imp_obd)); | |
200 | imp->imp_invalid = 1; | |
201 | imp->imp_generation++; | |
202 | spin_unlock(&imp->imp_lock); | |
203 | ||
204 | ptlrpc_abort_inflight(imp); | |
205 | obd_import_event(imp->imp_obd, imp, IMP_EVENT_INACTIVE); | |
d7e09d03 PT |
206 | } |
207 | ||
208 | /* | |
209 | * This acts as a barrier; all existing requests are rejected, and | |
210 | * no new requests will be accepted until the import is valid again. | |
211 | */ | |
212 | void ptlrpc_deactivate_import(struct obd_import *imp) | |
213 | { | |
214 | spin_lock(&imp->imp_lock); | |
215 | ptlrpc_deactivate_and_unlock_import(imp); | |
216 | } | |
217 | EXPORT_SYMBOL(ptlrpc_deactivate_import); | |
218 | ||
219 | static unsigned int | |
220 | ptlrpc_inflight_deadline(struct ptlrpc_request *req, time_t now) | |
221 | { | |
222 | long dl; | |
223 | ||
224 | if (!(((req->rq_phase == RQ_PHASE_RPC) && !req->rq_waiting) || | |
225 | (req->rq_phase == RQ_PHASE_BULK) || | |
226 | (req->rq_phase == RQ_PHASE_NEW))) | |
227 | return 0; | |
228 | ||
229 | if (req->rq_timedout) | |
230 | return 0; | |
231 | ||
232 | if (req->rq_phase == RQ_PHASE_NEW) | |
233 | dl = req->rq_sent; | |
234 | else | |
235 | dl = req->rq_deadline; | |
236 | ||
237 | if (dl <= now) | |
238 | return 0; | |
239 | ||
240 | return dl - now; | |
241 | } | |
242 | ||
243 | static unsigned int ptlrpc_inflight_timeout(struct obd_import *imp) | |
244 | { | |
245 | time_t now = cfs_time_current_sec(); | |
246 | struct list_head *tmp, *n; | |
247 | struct ptlrpc_request *req; | |
248 | unsigned int timeout = 0; | |
249 | ||
250 | spin_lock(&imp->imp_lock); | |
251 | list_for_each_safe(tmp, n, &imp->imp_sending_list) { | |
252 | req = list_entry(tmp, struct ptlrpc_request, rq_list); | |
253 | timeout = max(ptlrpc_inflight_deadline(req, now), timeout); | |
254 | } | |
255 | spin_unlock(&imp->imp_lock); | |
256 | return timeout; | |
257 | } | |
258 | ||
259 | /** | |
260 | * This function will invalidate the import, if necessary, then block | |
261 | * for all the RPC completions, and finally notify the obd to | |
262 | * invalidate its state (ie cancel locks, clear pending requests, | |
263 | * etc). | |
264 | */ | |
265 | void ptlrpc_invalidate_import(struct obd_import *imp) | |
266 | { | |
267 | struct list_head *tmp, *n; | |
268 | struct ptlrpc_request *req; | |
269 | struct l_wait_info lwi; | |
270 | unsigned int timeout; | |
271 | int rc; | |
272 | ||
273 | atomic_inc(&imp->imp_inval_count); | |
274 | ||
275 | if (!imp->imp_invalid || imp->imp_obd->obd_no_recov) | |
276 | ptlrpc_deactivate_import(imp); | |
277 | ||
278 | LASSERT(imp->imp_invalid); | |
279 | ||
280 | /* Wait forever until inflight == 0. We really can't do it another | |
281 | * way because in some cases we need to wait for very long reply | |
282 | * unlink. We can't do anything before that because there is really | |
283 | * no guarantee that some rdma transfer is not in progress right now. */ | |
284 | do { | |
285 | /* Calculate max timeout for waiting on rpcs to error | |
286 | * out. Use obd_timeout if calculated value is smaller | |
287 | * than it. */ | |
288 | if (!OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK)) { | |
289 | timeout = ptlrpc_inflight_timeout(imp); | |
290 | timeout += timeout / 3; | |
291 | ||
292 | if (timeout == 0) | |
293 | timeout = obd_timeout; | |
294 | } else { | |
295 | /* decrease the interval to increase race condition */ | |
296 | timeout = 1; | |
297 | } | |
298 | ||
299 | CDEBUG(D_RPCTRACE,"Sleeping %d sec for inflight to error out\n", | |
300 | timeout); | |
301 | ||
302 | /* Wait for all requests to error out and call completion | |
303 | * callbacks. Cap it at obd_timeout -- these should all | |
304 | * have been locally cancelled by ptlrpc_abort_inflight. */ | |
305 | lwi = LWI_TIMEOUT_INTERVAL( | |
306 | cfs_timeout_cap(cfs_time_seconds(timeout)), | |
307 | (timeout > 1)?cfs_time_seconds(1):cfs_time_seconds(1)/2, | |
308 | NULL, NULL); | |
309 | rc = l_wait_event(imp->imp_recovery_waitq, | |
310 | (atomic_read(&imp->imp_inflight) == 0), | |
311 | &lwi); | |
312 | if (rc) { | |
313 | const char *cli_tgt = obd2cli_tgt(imp->imp_obd); | |
314 | ||
315 | CERROR("%s: rc = %d waiting for callback (%d != 0)\n", | |
316 | cli_tgt, rc, | |
317 | atomic_read(&imp->imp_inflight)); | |
318 | ||
319 | spin_lock(&imp->imp_lock); | |
320 | if (atomic_read(&imp->imp_inflight) == 0) { | |
321 | int count = atomic_read(&imp->imp_unregistering); | |
322 | ||
323 | /* We know that "unregistering" rpcs only can | |
324 | * survive in sending or delaying lists (they | |
325 | * maybe waiting for long reply unlink in | |
326 | * sluggish nets). Let's check this. If there | |
327 | * is no inflight and unregistering != 0, this | |
328 | * is bug. */ | |
329 | LASSERTF(count == 0, "Some RPCs are still " | |
330 | "unregistering: %d\n", count); | |
331 | ||
332 | /* Let's save one loop as soon as inflight have | |
333 | * dropped to zero. No new inflights possible at | |
334 | * this point. */ | |
335 | rc = 0; | |
336 | } else { | |
337 | list_for_each_safe(tmp, n, | |
338 | &imp->imp_sending_list) { | |
339 | req = list_entry(tmp, | |
340 | struct ptlrpc_request, | |
341 | rq_list); | |
342 | DEBUG_REQ(D_ERROR, req, | |
343 | "still on sending list"); | |
344 | } | |
345 | list_for_each_safe(tmp, n, | |
346 | &imp->imp_delayed_list) { | |
347 | req = list_entry(tmp, | |
348 | struct ptlrpc_request, | |
349 | rq_list); | |
350 | DEBUG_REQ(D_ERROR, req, | |
351 | "still on delayed list"); | |
352 | } | |
353 | ||
354 | CERROR("%s: RPCs in \"%s\" phase found (%d). " | |
355 | "Network is sluggish? Waiting them " | |
356 | "to error out.\n", cli_tgt, | |
357 | ptlrpc_phase2str(RQ_PHASE_UNREGISTERING), | |
358 | atomic_read(&imp-> | |
359 | imp_unregistering)); | |
360 | } | |
361 | spin_unlock(&imp->imp_lock); | |
362 | } | |
363 | } while (rc != 0); | |
364 | ||
365 | /* | |
366 | * Let's additionally check that no new rpcs added to import in | |
367 | * "invalidate" state. | |
368 | */ | |
369 | LASSERT(atomic_read(&imp->imp_inflight) == 0); | |
370 | obd_import_event(imp->imp_obd, imp, IMP_EVENT_INVALIDATE); | |
371 | sptlrpc_import_flush_all_ctx(imp); | |
372 | ||
373 | atomic_dec(&imp->imp_inval_count); | |
374 | wake_up_all(&imp->imp_recovery_waitq); | |
375 | } | |
376 | EXPORT_SYMBOL(ptlrpc_invalidate_import); | |
377 | ||
378 | /* unset imp_invalid */ | |
379 | void ptlrpc_activate_import(struct obd_import *imp) | |
380 | { | |
381 | struct obd_device *obd = imp->imp_obd; | |
382 | ||
383 | spin_lock(&imp->imp_lock); | |
0b291b9a HZ |
384 | if (imp->imp_deactive != 0) { |
385 | spin_unlock(&imp->imp_lock); | |
386 | return; | |
387 | } | |
388 | ||
d7e09d03 | 389 | imp->imp_invalid = 0; |
d7e09d03 PT |
390 | spin_unlock(&imp->imp_lock); |
391 | obd_import_event(obd, imp, IMP_EVENT_ACTIVE); | |
392 | } | |
393 | EXPORT_SYMBOL(ptlrpc_activate_import); | |
394 | ||
395 | void ptlrpc_fail_import(struct obd_import *imp, __u32 conn_cnt) | |
396 | { | |
d7e09d03 PT |
397 | LASSERT(!imp->imp_dlm_fake); |
398 | ||
399 | if (ptlrpc_set_import_discon(imp, conn_cnt)) { | |
400 | if (!imp->imp_replayable) { | |
401 | CDEBUG(D_HA, "import %s@%s for %s not replayable, " | |
402 | "auto-deactivating\n", | |
403 | obd2cli_tgt(imp->imp_obd), | |
404 | imp->imp_connection->c_remote_uuid.uuid, | |
405 | imp->imp_obd->obd_name); | |
406 | ptlrpc_deactivate_import(imp); | |
407 | } | |
408 | ||
409 | CDEBUG(D_HA, "%s: waking up pinger\n", | |
410 | obd2cli_tgt(imp->imp_obd)); | |
411 | ||
412 | spin_lock(&imp->imp_lock); | |
413 | imp->imp_force_verify = 1; | |
414 | spin_unlock(&imp->imp_lock); | |
415 | ||
416 | ptlrpc_pinger_wake_up(); | |
417 | } | |
d7e09d03 PT |
418 | } |
419 | EXPORT_SYMBOL(ptlrpc_fail_import); | |
420 | ||
421 | int ptlrpc_reconnect_import(struct obd_import *imp) | |
422 | { | |
423 | ptlrpc_set_import_discon(imp, 0); | |
424 | /* Force a new connect attempt */ | |
425 | ptlrpc_invalidate_import(imp); | |
426 | /* Do a fresh connect next time by zeroing the handle */ | |
427 | ptlrpc_disconnect_import(imp, 1); | |
428 | /* Wait for all invalidate calls to finish */ | |
429 | if (atomic_read(&imp->imp_inval_count) > 0) { | |
430 | int rc; | |
431 | struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL); | |
432 | rc = l_wait_event(imp->imp_recovery_waitq, | |
433 | (atomic_read(&imp->imp_inval_count) == 0), | |
434 | &lwi); | |
435 | if (rc) | |
436 | CERROR("Interrupted, inval=%d\n", | |
437 | atomic_read(&imp->imp_inval_count)); | |
438 | } | |
439 | ||
440 | /* Allow reconnect attempts */ | |
441 | imp->imp_obd->obd_no_recov = 0; | |
442 | /* Remove 'invalid' flag */ | |
443 | ptlrpc_activate_import(imp); | |
444 | /* Attempt a new connect */ | |
445 | ptlrpc_recover_import(imp, NULL, 0); | |
446 | return 0; | |
447 | } | |
448 | EXPORT_SYMBOL(ptlrpc_reconnect_import); | |
449 | ||
450 | /** | |
451 | * Connection on import \a imp is changed to another one (if more than one is | |
452 | * present). We typically chose connection that we have not tried to connect to | |
453 | * the longest | |
454 | */ | |
455 | static int import_select_connection(struct obd_import *imp) | |
456 | { | |
457 | struct obd_import_conn *imp_conn = NULL, *conn; | |
458 | struct obd_export *dlmexp; | |
459 | char *target_start; | |
460 | int target_len, tried_all = 1; | |
d7e09d03 PT |
461 | |
462 | spin_lock(&imp->imp_lock); | |
463 | ||
464 | if (list_empty(&imp->imp_conn_list)) { | |
465 | CERROR("%s: no connections available\n", | |
466 | imp->imp_obd->obd_name); | |
467 | spin_unlock(&imp->imp_lock); | |
0a3bdb00 | 468 | return -EINVAL; |
d7e09d03 PT |
469 | } |
470 | ||
471 | list_for_each_entry(conn, &imp->imp_conn_list, oic_item) { | |
472 | CDEBUG(D_HA, "%s: connect to NID %s last attempt "LPU64"\n", | |
473 | imp->imp_obd->obd_name, | |
474 | libcfs_nid2str(conn->oic_conn->c_peer.nid), | |
475 | conn->oic_last_attempt); | |
476 | ||
477 | /* If we have not tried this connection since | |
478 | the last successful attempt, go with this one */ | |
479 | if ((conn->oic_last_attempt == 0) || | |
480 | cfs_time_beforeq_64(conn->oic_last_attempt, | |
481 | imp->imp_last_success_conn)) { | |
482 | imp_conn = conn; | |
483 | tried_all = 0; | |
484 | break; | |
485 | } | |
486 | ||
487 | /* If all of the connections have already been tried | |
488 | since the last successful connection; just choose the | |
489 | least recently used */ | |
490 | if (!imp_conn) | |
491 | imp_conn = conn; | |
492 | else if (cfs_time_before_64(conn->oic_last_attempt, | |
493 | imp_conn->oic_last_attempt)) | |
494 | imp_conn = conn; | |
495 | } | |
496 | ||
497 | /* if not found, simply choose the current one */ | |
498 | if (!imp_conn || imp->imp_force_reconnect) { | |
499 | LASSERT(imp->imp_conn_current); | |
500 | imp_conn = imp->imp_conn_current; | |
501 | tried_all = 0; | |
502 | } | |
503 | LASSERT(imp_conn->oic_conn); | |
504 | ||
505 | /* If we've tried everything, and we're back to the beginning of the | |
506 | list, increase our timeout and try again. It will be reset when | |
507 | we do finally connect. (FIXME: really we should wait for all network | |
508 | state associated with the last connection attempt to drain before | |
509 | trying to reconnect on it.) */ | |
510 | if (tried_all && (imp->imp_conn_list.next == &imp_conn->oic_item)) { | |
511 | struct adaptive_timeout *at = &imp->imp_at.iat_net_latency; | |
512 | if (at_get(at) < CONNECTION_SWITCH_MAX) { | |
513 | at_measured(at, at_get(at) + CONNECTION_SWITCH_INC); | |
514 | if (at_get(at) > CONNECTION_SWITCH_MAX) | |
515 | at_reset(at, CONNECTION_SWITCH_MAX); | |
516 | } | |
517 | LASSERT(imp_conn->oic_last_attempt); | |
518 | CDEBUG(D_HA, "%s: tried all connections, increasing latency " | |
519 | "to %ds\n", imp->imp_obd->obd_name, at_get(at)); | |
520 | } | |
521 | ||
522 | imp_conn->oic_last_attempt = cfs_time_current_64(); | |
523 | ||
524 | /* switch connection, don't mind if it's same as the current one */ | |
525 | if (imp->imp_connection) | |
526 | ptlrpc_connection_put(imp->imp_connection); | |
527 | imp->imp_connection = ptlrpc_connection_addref(imp_conn->oic_conn); | |
528 | ||
529 | dlmexp = class_conn2export(&imp->imp_dlm_handle); | |
530 | LASSERT(dlmexp != NULL); | |
531 | if (dlmexp->exp_connection) | |
532 | ptlrpc_connection_put(dlmexp->exp_connection); | |
533 | dlmexp->exp_connection = ptlrpc_connection_addref(imp_conn->oic_conn); | |
534 | class_export_put(dlmexp); | |
535 | ||
536 | if (imp->imp_conn_current != imp_conn) { | |
537 | if (imp->imp_conn_current) { | |
538 | deuuidify(obd2cli_tgt(imp->imp_obd), NULL, | |
539 | &target_start, &target_len); | |
540 | ||
541 | CDEBUG(D_HA, "%s: Connection changing to" | |
542 | " %.*s (at %s)\n", | |
543 | imp->imp_obd->obd_name, | |
544 | target_len, target_start, | |
545 | libcfs_nid2str(imp_conn->oic_conn->c_peer.nid)); | |
546 | } | |
547 | ||
548 | imp->imp_conn_current = imp_conn; | |
549 | } | |
550 | ||
551 | CDEBUG(D_HA, "%s: import %p using connection %s/%s\n", | |
552 | imp->imp_obd->obd_name, imp, imp_conn->oic_uuid.uuid, | |
553 | libcfs_nid2str(imp_conn->oic_conn->c_peer.nid)); | |
554 | ||
555 | spin_unlock(&imp->imp_lock); | |
556 | ||
0a3bdb00 | 557 | return 0; |
d7e09d03 PT |
558 | } |
559 | ||
560 | /* | |
561 | * must be called under imp_lock | |
562 | */ | |
563 | static int ptlrpc_first_transno(struct obd_import *imp, __u64 *transno) | |
564 | { | |
565 | struct ptlrpc_request *req; | |
566 | struct list_head *tmp; | |
567 | ||
63d42578 HZ |
568 | /* The requests in committed_list always have smaller transnos than |
569 | * the requests in replay_list */ | |
570 | if (!list_empty(&imp->imp_committed_list)) { | |
571 | tmp = imp->imp_committed_list.next; | |
572 | req = list_entry(tmp, struct ptlrpc_request, rq_replay_list); | |
573 | *transno = req->rq_transno; | |
574 | if (req->rq_transno == 0) { | |
575 | DEBUG_REQ(D_ERROR, req, | |
576 | "zero transno in committed_list"); | |
577 | LBUG(); | |
578 | } | |
579 | return 1; | |
d7e09d03 | 580 | } |
63d42578 HZ |
581 | if (!list_empty(&imp->imp_replay_list)) { |
582 | tmp = imp->imp_replay_list.next; | |
583 | req = list_entry(tmp, struct ptlrpc_request, rq_replay_list); | |
584 | *transno = req->rq_transno; | |
585 | if (req->rq_transno == 0) { | |
586 | DEBUG_REQ(D_ERROR, req, "zero transno in replay_list"); | |
587 | LBUG(); | |
588 | } | |
589 | return 1; | |
590 | } | |
591 | return 0; | |
d7e09d03 PT |
592 | } |
593 | ||
594 | /** | |
595 | * Attempt to (re)connect import \a imp. This includes all preparations, | |
596 | * initializing CONNECT RPC request and passing it to ptlrpcd for | |
597 | * actual sending. | |
598 | * Returns 0 on success or error code. | |
599 | */ | |
600 | int ptlrpc_connect_import(struct obd_import *imp) | |
601 | { | |
602 | struct obd_device *obd = imp->imp_obd; | |
603 | int initial_connect = 0; | |
604 | int set_transno = 0; | |
605 | __u64 committed_before_reconnect = 0; | |
606 | struct ptlrpc_request *request; | |
607 | char *bufs[] = { NULL, | |
608 | obd2cli_tgt(imp->imp_obd), | |
609 | obd->obd_uuid.uuid, | |
610 | (char *)&imp->imp_dlm_handle, | |
611 | (char *)&imp->imp_connect_data }; | |
612 | struct ptlrpc_connect_async_args *aa; | |
613 | int rc; | |
d7e09d03 PT |
614 | |
615 | spin_lock(&imp->imp_lock); | |
616 | if (imp->imp_state == LUSTRE_IMP_CLOSED) { | |
617 | spin_unlock(&imp->imp_lock); | |
618 | CERROR("can't connect to a closed import\n"); | |
0a3bdb00 | 619 | return -EINVAL; |
d7e09d03 PT |
620 | } else if (imp->imp_state == LUSTRE_IMP_FULL) { |
621 | spin_unlock(&imp->imp_lock); | |
622 | CERROR("already connected\n"); | |
0a3bdb00 | 623 | return 0; |
d7e09d03 PT |
624 | } else if (imp->imp_state == LUSTRE_IMP_CONNECTING) { |
625 | spin_unlock(&imp->imp_lock); | |
626 | CERROR("already connecting\n"); | |
0a3bdb00 | 627 | return -EALREADY; |
d7e09d03 PT |
628 | } |
629 | ||
630 | IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_CONNECTING); | |
631 | ||
632 | imp->imp_conn_cnt++; | |
633 | imp->imp_resend_replay = 0; | |
634 | ||
635 | if (!lustre_handle_is_used(&imp->imp_remote_handle)) | |
636 | initial_connect = 1; | |
637 | else | |
638 | committed_before_reconnect = imp->imp_peer_committed_transno; | |
639 | ||
640 | set_transno = ptlrpc_first_transno(imp, | |
641 | &imp->imp_connect_data.ocd_transno); | |
642 | spin_unlock(&imp->imp_lock); | |
643 | ||
644 | rc = import_select_connection(imp); | |
645 | if (rc) | |
646 | GOTO(out, rc); | |
647 | ||
648 | rc = sptlrpc_import_sec_adapt(imp, NULL, 0); | |
649 | if (rc) | |
650 | GOTO(out, rc); | |
651 | ||
652 | /* Reset connect flags to the originally requested flags, in case | |
653 | * the server is updated on-the-fly we will get the new features. */ | |
654 | imp->imp_connect_data.ocd_connect_flags = imp->imp_connect_flags_orig; | |
655 | /* Reset ocd_version each time so the server knows the exact versions */ | |
656 | imp->imp_connect_data.ocd_version = LUSTRE_VERSION_CODE; | |
657 | imp->imp_msghdr_flags &= ~MSGHDR_AT_SUPPORT; | |
658 | imp->imp_msghdr_flags &= ~MSGHDR_CKSUM_INCOMPAT18; | |
659 | ||
660 | rc = obd_reconnect(NULL, imp->imp_obd->obd_self_export, obd, | |
661 | &obd->obd_uuid, &imp->imp_connect_data, NULL); | |
662 | if (rc) | |
663 | GOTO(out, rc); | |
664 | ||
665 | request = ptlrpc_request_alloc(imp, &RQF_MDS_CONNECT); | |
666 | if (request == NULL) | |
667 | GOTO(out, rc = -ENOMEM); | |
668 | ||
669 | rc = ptlrpc_request_bufs_pack(request, LUSTRE_OBD_VERSION, | |
670 | imp->imp_connect_op, bufs, NULL); | |
671 | if (rc) { | |
672 | ptlrpc_request_free(request); | |
673 | GOTO(out, rc); | |
674 | } | |
675 | ||
676 | /* Report the rpc service time to the server so that it knows how long | |
677 | * to wait for clients to join recovery */ | |
678 | lustre_msg_set_service_time(request->rq_reqmsg, | |
679 | at_timeout2est(request->rq_timeout)); | |
680 | ||
681 | /* The amount of time we give the server to process the connect req. | |
682 | * import_select_connection will increase the net latency on | |
683 | * repeated reconnect attempts to cover slow networks. | |
684 | * We override/ignore the server rpc completion estimate here, | |
685 | * which may be large if this is a reconnect attempt */ | |
686 | request->rq_timeout = INITIAL_CONNECT_TIMEOUT; | |
687 | lustre_msg_set_timeout(request->rq_reqmsg, request->rq_timeout); | |
688 | ||
689 | lustre_msg_add_op_flags(request->rq_reqmsg, MSG_CONNECT_NEXT_VER); | |
690 | ||
691 | request->rq_no_resend = request->rq_no_delay = 1; | |
692 | request->rq_send_state = LUSTRE_IMP_CONNECTING; | |
693 | /* Allow a slightly larger reply for future growth compatibility */ | |
694 | req_capsule_set_size(&request->rq_pill, &RMF_CONNECT_DATA, RCL_SERVER, | |
695 | sizeof(struct obd_connect_data)+16*sizeof(__u64)); | |
696 | ptlrpc_request_set_replen(request); | |
697 | request->rq_interpret_reply = ptlrpc_connect_interpret; | |
698 | ||
3949015e | 699 | CLASSERT(sizeof(*aa) <= sizeof(request->rq_async_args)); |
d7e09d03 | 700 | aa = ptlrpc_req_async_args(request); |
ec83e611 | 701 | memset(aa, 0, sizeof(*aa)); |
d7e09d03 PT |
702 | |
703 | aa->pcaa_peer_committed = committed_before_reconnect; | |
704 | aa->pcaa_initial_connect = initial_connect; | |
705 | ||
706 | if (aa->pcaa_initial_connect) { | |
707 | spin_lock(&imp->imp_lock); | |
708 | imp->imp_replayable = 1; | |
709 | spin_unlock(&imp->imp_lock); | |
710 | lustre_msg_add_op_flags(request->rq_reqmsg, | |
711 | MSG_CONNECT_INITIAL); | |
712 | } | |
713 | ||
714 | if (set_transno) | |
715 | lustre_msg_add_op_flags(request->rq_reqmsg, | |
716 | MSG_CONNECT_TRANSNO); | |
717 | ||
718 | DEBUG_REQ(D_RPCTRACE, request, "(re)connect request (timeout %d)", | |
719 | request->rq_timeout); | |
720 | ptlrpcd_add_req(request, PDL_POLICY_ROUND, -1); | |
721 | rc = 0; | |
722 | out: | |
723 | if (rc != 0) { | |
724 | IMPORT_SET_STATE(imp, LUSTRE_IMP_DISCON); | |
725 | } | |
726 | ||
0a3bdb00 | 727 | return rc; |
d7e09d03 PT |
728 | } |
729 | EXPORT_SYMBOL(ptlrpc_connect_import); | |
730 | ||
731 | static void ptlrpc_maybe_ping_import_soon(struct obd_import *imp) | |
732 | { | |
733 | int force_verify; | |
734 | ||
735 | spin_lock(&imp->imp_lock); | |
736 | force_verify = imp->imp_force_verify != 0; | |
737 | spin_unlock(&imp->imp_lock); | |
738 | ||
739 | if (force_verify) | |
740 | ptlrpc_pinger_wake_up(); | |
741 | } | |
742 | ||
743 | static int ptlrpc_busy_reconnect(int rc) | |
744 | { | |
745 | return (rc == -EBUSY) || (rc == -EAGAIN); | |
746 | } | |
747 | ||
748 | /** | |
749 | * interpret_reply callback for connect RPCs. | |
750 | * Looks into returned status of connect operation and decides | |
751 | * what to do with the import - i.e enter recovery, promote it to | |
752 | * full state for normal operations of disconnect it due to an error. | |
753 | */ | |
754 | static int ptlrpc_connect_interpret(const struct lu_env *env, | |
755 | struct ptlrpc_request *request, | |
756 | void *data, int rc) | |
757 | { | |
758 | struct ptlrpc_connect_async_args *aa = data; | |
759 | struct obd_import *imp = request->rq_import; | |
760 | struct client_obd *cli = &imp->imp_obd->u.cli; | |
761 | struct lustre_handle old_hdl; | |
762 | __u64 old_connect_flags; | |
763 | int msg_flags; | |
764 | struct obd_connect_data *ocd; | |
765 | struct obd_export *exp; | |
766 | int ret; | |
d7e09d03 PT |
767 | |
768 | spin_lock(&imp->imp_lock); | |
769 | if (imp->imp_state == LUSTRE_IMP_CLOSED) { | |
770 | imp->imp_connect_tried = 1; | |
771 | spin_unlock(&imp->imp_lock); | |
0a3bdb00 | 772 | return 0; |
d7e09d03 PT |
773 | } |
774 | ||
775 | if (rc) { | |
776 | /* if this reconnect to busy export - not need select new target | |
777 | * for connecting*/ | |
778 | imp->imp_force_reconnect = ptlrpc_busy_reconnect(rc); | |
779 | spin_unlock(&imp->imp_lock); | |
780 | ptlrpc_maybe_ping_import_soon(imp); | |
781 | GOTO(out, rc); | |
782 | } | |
783 | spin_unlock(&imp->imp_lock); | |
784 | ||
785 | LASSERT(imp->imp_conn_current); | |
786 | ||
787 | msg_flags = lustre_msg_get_op_flags(request->rq_repmsg); | |
788 | ||
789 | ret = req_capsule_get_size(&request->rq_pill, &RMF_CONNECT_DATA, | |
790 | RCL_SERVER); | |
791 | /* server replied obd_connect_data is always bigger */ | |
792 | ocd = req_capsule_server_sized_get(&request->rq_pill, | |
793 | &RMF_CONNECT_DATA, ret); | |
794 | ||
795 | if (ocd == NULL) { | |
796 | CERROR("%s: no connect data from server\n", | |
797 | imp->imp_obd->obd_name); | |
798 | rc = -EPROTO; | |
799 | GOTO(out, rc); | |
800 | } | |
801 | ||
802 | spin_lock(&imp->imp_lock); | |
803 | ||
804 | /* All imports are pingable */ | |
805 | imp->imp_pingable = 1; | |
806 | imp->imp_force_reconnect = 0; | |
807 | imp->imp_force_verify = 0; | |
808 | ||
809 | imp->imp_connect_data = *ocd; | |
810 | ||
811 | CDEBUG(D_HA, "%s: connect to target with instance %u\n", | |
812 | imp->imp_obd->obd_name, ocd->ocd_instance); | |
813 | exp = class_conn2export(&imp->imp_dlm_handle); | |
814 | ||
815 | spin_unlock(&imp->imp_lock); | |
816 | ||
817 | /* check that server granted subset of flags we asked for. */ | |
818 | if ((ocd->ocd_connect_flags & imp->imp_connect_flags_orig) != | |
819 | ocd->ocd_connect_flags) { | |
820 | CERROR("%s: Server didn't granted asked subset of flags: " | |
821 | "asked="LPX64" grranted="LPX64"\n", | |
822 | imp->imp_obd->obd_name,imp->imp_connect_flags_orig, | |
823 | ocd->ocd_connect_flags); | |
824 | GOTO(out, rc = -EPROTO); | |
825 | } | |
826 | ||
827 | if (!exp) { | |
828 | /* This could happen if export is cleaned during the | |
829 | connect attempt */ | |
830 | CERROR("%s: missing export after connect\n", | |
831 | imp->imp_obd->obd_name); | |
832 | GOTO(out, rc = -ENODEV); | |
833 | } | |
834 | old_connect_flags = exp_connect_flags(exp); | |
835 | exp->exp_connect_data = *ocd; | |
836 | imp->imp_obd->obd_self_export->exp_connect_data = *ocd; | |
837 | class_export_put(exp); | |
838 | ||
839 | obd_import_event(imp->imp_obd, imp, IMP_EVENT_OCD); | |
840 | ||
841 | if (aa->pcaa_initial_connect) { | |
842 | spin_lock(&imp->imp_lock); | |
843 | if (msg_flags & MSG_CONNECT_REPLAYABLE) { | |
844 | imp->imp_replayable = 1; | |
845 | spin_unlock(&imp->imp_lock); | |
846 | CDEBUG(D_HA, "connected to replayable target: %s\n", | |
847 | obd2cli_tgt(imp->imp_obd)); | |
848 | } else { | |
849 | imp->imp_replayable = 0; | |
850 | spin_unlock(&imp->imp_lock); | |
851 | } | |
852 | ||
853 | /* if applies, adjust the imp->imp_msg_magic here | |
854 | * according to reply flags */ | |
855 | ||
856 | imp->imp_remote_handle = | |
857 | *lustre_msg_get_handle(request->rq_repmsg); | |
858 | ||
859 | /* Initial connects are allowed for clients with non-random | |
860 | * uuids when servers are in recovery. Simply signal the | |
861 | * servers replay is complete and wait in REPLAY_WAIT. */ | |
862 | if (msg_flags & MSG_CONNECT_RECOVERING) { | |
863 | CDEBUG(D_HA, "connect to %s during recovery\n", | |
864 | obd2cli_tgt(imp->imp_obd)); | |
865 | IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY_LOCKS); | |
866 | } else { | |
867 | IMPORT_SET_STATE(imp, LUSTRE_IMP_FULL); | |
868 | ptlrpc_activate_import(imp); | |
869 | } | |
870 | ||
871 | GOTO(finish, rc = 0); | |
872 | } | |
873 | ||
874 | /* Determine what recovery state to move the import to. */ | |
875 | if (MSG_CONNECT_RECONNECT & msg_flags) { | |
876 | memset(&old_hdl, 0, sizeof(old_hdl)); | |
877 | if (!memcmp(&old_hdl, lustre_msg_get_handle(request->rq_repmsg), | |
3949015e | 878 | sizeof(old_hdl))) { |
d7e09d03 PT |
879 | LCONSOLE_WARN("Reconnect to %s (at @%s) failed due " |
880 | "bad handle "LPX64"\n", | |
881 | obd2cli_tgt(imp->imp_obd), | |
882 | imp->imp_connection->c_remote_uuid.uuid, | |
883 | imp->imp_dlm_handle.cookie); | |
884 | GOTO(out, rc = -ENOTCONN); | |
885 | } | |
886 | ||
887 | if (memcmp(&imp->imp_remote_handle, | |
888 | lustre_msg_get_handle(request->rq_repmsg), | |
889 | sizeof(imp->imp_remote_handle))) { | |
890 | int level = msg_flags & MSG_CONNECT_RECOVERING ? | |
891 | D_HA : D_WARNING; | |
892 | ||
893 | /* Bug 16611/14775: if server handle have changed, | |
894 | * that means some sort of disconnection happened. | |
895 | * If the server is not in recovery, that also means it | |
896 | * already erased all of our state because of previous | |
897 | * eviction. If it is in recovery - we are safe to | |
898 | * participate since we can reestablish all of our state | |
899 | * with server again */ | |
900 | if ((MSG_CONNECT_RECOVERING & msg_flags)) { | |
901 | CDEBUG(level,"%s@%s changed server handle from " | |
902 | LPX64" to "LPX64 | |
903 | " but is still in recovery\n", | |
904 | obd2cli_tgt(imp->imp_obd), | |
905 | imp->imp_connection->c_remote_uuid.uuid, | |
906 | imp->imp_remote_handle.cookie, | |
907 | lustre_msg_get_handle( | |
908 | request->rq_repmsg)->cookie); | |
909 | } else { | |
910 | LCONSOLE_WARN("Evicted from %s (at %s) " | |
911 | "after server handle changed from " | |
912 | LPX64" to "LPX64"\n", | |
913 | obd2cli_tgt(imp->imp_obd), | |
914 | imp->imp_connection-> \ | |
915 | c_remote_uuid.uuid, | |
916 | imp->imp_remote_handle.cookie, | |
917 | lustre_msg_get_handle( | |
918 | request->rq_repmsg)->cookie); | |
919 | } | |
920 | ||
921 | ||
922 | imp->imp_remote_handle = | |
923 | *lustre_msg_get_handle(request->rq_repmsg); | |
924 | ||
925 | if (!(MSG_CONNECT_RECOVERING & msg_flags)) { | |
926 | IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED); | |
927 | GOTO(finish, rc = 0); | |
928 | } | |
929 | ||
930 | } else { | |
931 | CDEBUG(D_HA, "reconnected to %s@%s after partition\n", | |
932 | obd2cli_tgt(imp->imp_obd), | |
933 | imp->imp_connection->c_remote_uuid.uuid); | |
934 | } | |
935 | ||
936 | if (imp->imp_invalid) { | |
937 | CDEBUG(D_HA, "%s: reconnected but import is invalid; " | |
938 | "marking evicted\n", imp->imp_obd->obd_name); | |
939 | IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED); | |
940 | } else if (MSG_CONNECT_RECOVERING & msg_flags) { | |
941 | CDEBUG(D_HA, "%s: reconnected to %s during replay\n", | |
942 | imp->imp_obd->obd_name, | |
943 | obd2cli_tgt(imp->imp_obd)); | |
944 | ||
945 | spin_lock(&imp->imp_lock); | |
946 | imp->imp_resend_replay = 1; | |
947 | spin_unlock(&imp->imp_lock); | |
948 | ||
949 | IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY); | |
950 | } else { | |
951 | IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER); | |
952 | } | |
953 | } else if ((MSG_CONNECT_RECOVERING & msg_flags) && !imp->imp_invalid) { | |
954 | LASSERT(imp->imp_replayable); | |
955 | imp->imp_remote_handle = | |
956 | *lustre_msg_get_handle(request->rq_repmsg); | |
957 | imp->imp_last_replay_transno = 0; | |
958 | IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY); | |
959 | } else { | |
960 | DEBUG_REQ(D_HA, request, "%s: evicting (reconnect/recover flags" | |
961 | " not set: %x)", imp->imp_obd->obd_name, msg_flags); | |
962 | imp->imp_remote_handle = | |
963 | *lustre_msg_get_handle(request->rq_repmsg); | |
964 | IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED); | |
965 | } | |
966 | ||
967 | /* Sanity checks for a reconnected import. */ | |
968 | if (!(imp->imp_replayable) != !(msg_flags & MSG_CONNECT_REPLAYABLE)) { | |
969 | CERROR("imp_replayable flag does not match server " | |
970 | "after reconnect. We should LBUG right here.\n"); | |
971 | } | |
972 | ||
973 | if (lustre_msg_get_last_committed(request->rq_repmsg) > 0 && | |
974 | lustre_msg_get_last_committed(request->rq_repmsg) < | |
975 | aa->pcaa_peer_committed) { | |
976 | CERROR("%s went back in time (transno "LPD64 | |
977 | " was previously committed, server now claims "LPD64 | |
978 | ")! See https://bugzilla.lustre.org/show_bug.cgi?" | |
979 | "id=9646\n", | |
980 | obd2cli_tgt(imp->imp_obd), aa->pcaa_peer_committed, | |
981 | lustre_msg_get_last_committed(request->rq_repmsg)); | |
982 | } | |
983 | ||
984 | finish: | |
985 | rc = ptlrpc_import_recovery_state_machine(imp); | |
986 | if (rc != 0) { | |
987 | if (rc == -ENOTCONN) { | |
988 | CDEBUG(D_HA, "evicted/aborted by %s@%s during recovery;" | |
989 | "invalidating and reconnecting\n", | |
990 | obd2cli_tgt(imp->imp_obd), | |
991 | imp->imp_connection->c_remote_uuid.uuid); | |
992 | ptlrpc_connect_import(imp); | |
993 | imp->imp_connect_tried = 1; | |
0a3bdb00 | 994 | return 0; |
d7e09d03 PT |
995 | } |
996 | } else { | |
997 | ||
998 | spin_lock(&imp->imp_lock); | |
999 | list_del(&imp->imp_conn_current->oic_item); | |
1000 | list_add(&imp->imp_conn_current->oic_item, | |
1001 | &imp->imp_conn_list); | |
1002 | imp->imp_last_success_conn = | |
1003 | imp->imp_conn_current->oic_last_attempt; | |
1004 | ||
1005 | spin_unlock(&imp->imp_lock); | |
1006 | ||
1007 | if (!ocd->ocd_ibits_known && | |
1008 | ocd->ocd_connect_flags & OBD_CONNECT_IBITS) | |
1009 | CERROR("Inodebits aware server returned zero compatible" | |
1010 | " bits?\n"); | |
1011 | ||
1012 | if ((ocd->ocd_connect_flags & OBD_CONNECT_VERSION) && | |
1013 | (ocd->ocd_version > LUSTRE_VERSION_CODE + | |
1014 | LUSTRE_VERSION_OFFSET_WARN || | |
1015 | ocd->ocd_version < LUSTRE_VERSION_CODE - | |
1016 | LUSTRE_VERSION_OFFSET_WARN)) { | |
1017 | /* Sigh, some compilers do not like #ifdef in the middle | |
1018 | of macro arguments */ | |
1019 | const char *older = "older. Consider upgrading server " | |
1020 | "or downgrading client"; | |
1021 | const char *newer = "newer than client version. " | |
1022 | "Consider upgrading client"; | |
1023 | ||
1024 | LCONSOLE_WARN("Server %s version (%d.%d.%d.%d) " | |
1025 | "is much %s (%s)\n", | |
1026 | obd2cli_tgt(imp->imp_obd), | |
1027 | OBD_OCD_VERSION_MAJOR(ocd->ocd_version), | |
1028 | OBD_OCD_VERSION_MINOR(ocd->ocd_version), | |
1029 | OBD_OCD_VERSION_PATCH(ocd->ocd_version), | |
1030 | OBD_OCD_VERSION_FIX(ocd->ocd_version), | |
1031 | ocd->ocd_version > LUSTRE_VERSION_CODE ? | |
1032 | newer : older, LUSTRE_VERSION_STRING); | |
1033 | } | |
1034 | ||
1035 | #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 2, 50, 0) | |
1036 | /* Check if server has LU-1252 fix applied to not always swab | |
1037 | * the IR MNE entries. Do this only once per connection. This | |
1038 | * fixup is version-limited, because we don't want to carry the | |
1039 | * OBD_CONNECT_MNE_SWAB flag around forever, just so long as we | |
1040 | * need interop with unpatched 2.2 servers. For newer servers, | |
1041 | * the client will do MNE swabbing only as needed. LU-1644 */ | |
1042 | if (unlikely((ocd->ocd_connect_flags & OBD_CONNECT_VERSION) && | |
1043 | !(ocd->ocd_connect_flags & OBD_CONNECT_MNE_SWAB) && | |
1044 | OBD_OCD_VERSION_MAJOR(ocd->ocd_version) == 2 && | |
1045 | OBD_OCD_VERSION_MINOR(ocd->ocd_version) == 2 && | |
1046 | OBD_OCD_VERSION_PATCH(ocd->ocd_version) < 55 && | |
1047 | strcmp(imp->imp_obd->obd_type->typ_name, | |
1048 | LUSTRE_MGC_NAME) == 0)) | |
1049 | imp->imp_need_mne_swab = 1; | |
1050 | else /* clear if server was upgraded since last connect */ | |
1051 | imp->imp_need_mne_swab = 0; | |
1052 | #else | |
1053 | #warning "LU-1644: Remove old OBD_CONNECT_MNE_SWAB fixup and imp_need_mne_swab" | |
1054 | #endif | |
1055 | ||
1056 | if (ocd->ocd_connect_flags & OBD_CONNECT_CKSUM) { | |
1057 | /* We sent to the server ocd_cksum_types with bits set | |
1058 | * for algorithms we understand. The server masked off | |
1059 | * the checksum types it doesn't support */ | |
1060 | if ((ocd->ocd_cksum_types & | |
1061 | cksum_types_supported_client()) == 0) { | |
1062 | LCONSOLE_WARN("The negotiation of the checksum " | |
b6da17f3 | 1063 | "algorithm to use with server %s " |
d7e09d03 PT |
1064 | "failed (%x/%x), disabling " |
1065 | "checksums\n", | |
1066 | obd2cli_tgt(imp->imp_obd), | |
1067 | ocd->ocd_cksum_types, | |
1068 | cksum_types_supported_client()); | |
1069 | cli->cl_checksum = 0; | |
1070 | cli->cl_supp_cksum_types = OBD_CKSUM_ADLER; | |
1071 | } else { | |
1072 | cli->cl_supp_cksum_types = ocd->ocd_cksum_types; | |
1073 | } | |
1074 | } else { | |
1075 | /* The server does not support OBD_CONNECT_CKSUM. | |
1076 | * Enforce ADLER for backward compatibility*/ | |
1077 | cli->cl_supp_cksum_types = OBD_CKSUM_ADLER; | |
1078 | } | |
1079 | cli->cl_cksum_type =cksum_type_select(cli->cl_supp_cksum_types); | |
1080 | ||
1081 | if (ocd->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) | |
1082 | cli->cl_max_pages_per_rpc = | |
1083 | min(ocd->ocd_brw_size >> PAGE_CACHE_SHIFT, | |
1084 | cli->cl_max_pages_per_rpc); | |
1085 | else if (imp->imp_connect_op == MDS_CONNECT || | |
1086 | imp->imp_connect_op == MGS_CONNECT) | |
1087 | cli->cl_max_pages_per_rpc = 1; | |
1088 | ||
1089 | /* Reset ns_connect_flags only for initial connect. It might be | |
1090 | * changed in while using FS and if we reset it in reconnect | |
1091 | * this leads to losing user settings done before such as | |
1092 | * disable lru_resize, etc. */ | |
1093 | if (old_connect_flags != exp_connect_flags(exp) || | |
1094 | aa->pcaa_initial_connect) { | |
1095 | CDEBUG(D_HA, "%s: Resetting ns_connect_flags to server " | |
1096 | "flags: "LPX64"\n", imp->imp_obd->obd_name, | |
1097 | ocd->ocd_connect_flags); | |
1098 | imp->imp_obd->obd_namespace->ns_connect_flags = | |
1099 | ocd->ocd_connect_flags; | |
1100 | imp->imp_obd->obd_namespace->ns_orig_connect_flags = | |
1101 | ocd->ocd_connect_flags; | |
1102 | } | |
1103 | ||
1104 | if ((ocd->ocd_connect_flags & OBD_CONNECT_AT) && | |
1105 | (imp->imp_msg_magic == LUSTRE_MSG_MAGIC_V2)) | |
1106 | /* We need a per-message support flag, because | |
1107 | a. we don't know if the incoming connect reply | |
1108 | supports AT or not (in reply_in_callback) | |
1109 | until we unpack it. | |
1110 | b. failovered server means export and flags are gone | |
1111 | (in ptlrpc_send_reply). | |
1112 | Can only be set when we know AT is supported at | |
1113 | both ends */ | |
1114 | imp->imp_msghdr_flags |= MSGHDR_AT_SUPPORT; | |
1115 | else | |
1116 | imp->imp_msghdr_flags &= ~MSGHDR_AT_SUPPORT; | |
1117 | ||
1118 | if ((ocd->ocd_connect_flags & OBD_CONNECT_FULL20) && | |
1119 | (imp->imp_msg_magic == LUSTRE_MSG_MAGIC_V2)) | |
1120 | imp->imp_msghdr_flags |= MSGHDR_CKSUM_INCOMPAT18; | |
1121 | else | |
1122 | imp->imp_msghdr_flags &= ~MSGHDR_CKSUM_INCOMPAT18; | |
1123 | ||
1124 | LASSERT((cli->cl_max_pages_per_rpc <= PTLRPC_MAX_BRW_PAGES) && | |
1125 | (cli->cl_max_pages_per_rpc > 0)); | |
1126 | } | |
1127 | ||
1128 | out: | |
1129 | imp->imp_connect_tried = 1; | |
1130 | ||
1131 | if (rc != 0) { | |
1132 | IMPORT_SET_STATE(imp, LUSTRE_IMP_DISCON); | |
1133 | if (rc == -EACCES) { | |
1134 | /* | |
1135 | * Give up trying to reconnect | |
1136 | * EACCES means client has no permission for connection | |
1137 | */ | |
1138 | imp->imp_obd->obd_no_recov = 1; | |
1139 | ptlrpc_deactivate_import(imp); | |
1140 | } | |
1141 | ||
1142 | if (rc == -EPROTO) { | |
1143 | struct obd_connect_data *ocd; | |
1144 | ||
1145 | /* reply message might not be ready */ | |
1146 | if (request->rq_repmsg == NULL) | |
0a3bdb00 | 1147 | return -EPROTO; |
d7e09d03 PT |
1148 | |
1149 | ocd = req_capsule_server_get(&request->rq_pill, | |
1150 | &RMF_CONNECT_DATA); | |
1151 | if (ocd && | |
1152 | (ocd->ocd_connect_flags & OBD_CONNECT_VERSION) && | |
1153 | (ocd->ocd_version != LUSTRE_VERSION_CODE)) { | |
532118c0 KM |
1154 | /* |
1155 | * Actually servers are only supposed to refuse | |
1156 | * connection from liblustre clients, so we | |
1157 | * should never see this from VFS context | |
1158 | */ | |
d7e09d03 PT |
1159 | LCONSOLE_ERROR_MSG(0x16a, "Server %s version " |
1160 | "(%d.%d.%d.%d)" | |
1161 | " refused connection from this client " | |
1162 | "with an incompatible version (%s). " | |
1163 | "Client must be recompiled\n", | |
1164 | obd2cli_tgt(imp->imp_obd), | |
1165 | OBD_OCD_VERSION_MAJOR(ocd->ocd_version), | |
1166 | OBD_OCD_VERSION_MINOR(ocd->ocd_version), | |
1167 | OBD_OCD_VERSION_PATCH(ocd->ocd_version), | |
1168 | OBD_OCD_VERSION_FIX(ocd->ocd_version), | |
1169 | LUSTRE_VERSION_STRING); | |
1170 | ptlrpc_deactivate_import(imp); | |
1171 | IMPORT_SET_STATE(imp, LUSTRE_IMP_CLOSED); | |
1172 | } | |
0a3bdb00 | 1173 | return -EPROTO; |
d7e09d03 PT |
1174 | } |
1175 | ||
1176 | ptlrpc_maybe_ping_import_soon(imp); | |
1177 | ||
1178 | CDEBUG(D_HA, "recovery of %s on %s failed (%d)\n", | |
1179 | obd2cli_tgt(imp->imp_obd), | |
1180 | (char *)imp->imp_connection->c_remote_uuid.uuid, rc); | |
1181 | } | |
1182 | ||
1183 | wake_up_all(&imp->imp_recovery_waitq); | |
0a3bdb00 | 1184 | return rc; |
d7e09d03 PT |
1185 | } |
1186 | ||
1187 | /** | |
1188 | * interpret callback for "completed replay" RPCs. | |
1189 | * \see signal_completed_replay | |
1190 | */ | |
1191 | static int completed_replay_interpret(const struct lu_env *env, | |
1192 | struct ptlrpc_request *req, | |
1193 | void * data, int rc) | |
1194 | { | |
d7e09d03 PT |
1195 | atomic_dec(&req->rq_import->imp_replay_inflight); |
1196 | if (req->rq_status == 0 && | |
1197 | !req->rq_import->imp_vbr_failed) { | |
1198 | ptlrpc_import_recovery_state_machine(req->rq_import); | |
1199 | } else { | |
1200 | if (req->rq_import->imp_vbr_failed) { | |
1201 | CDEBUG(D_WARNING, | |
1202 | "%s: version recovery fails, reconnecting\n", | |
1203 | req->rq_import->imp_obd->obd_name); | |
1204 | } else { | |
1205 | CDEBUG(D_HA, "%s: LAST_REPLAY message error: %d, " | |
1206 | "reconnecting\n", | |
1207 | req->rq_import->imp_obd->obd_name, | |
1208 | req->rq_status); | |
1209 | } | |
1210 | ptlrpc_connect_import(req->rq_import); | |
1211 | } | |
1212 | ||
0a3bdb00 | 1213 | return 0; |
d7e09d03 PT |
1214 | } |
1215 | ||
1216 | /** | |
1217 | * Let server know that we have no requests to replay anymore. | |
1218 | * Achieved by just sending a PING request | |
1219 | */ | |
1220 | static int signal_completed_replay(struct obd_import *imp) | |
1221 | { | |
1222 | struct ptlrpc_request *req; | |
d7e09d03 PT |
1223 | |
1224 | if (unlikely(OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_FINISH_REPLAY))) | |
0a3bdb00 | 1225 | return 0; |
d7e09d03 PT |
1226 | |
1227 | LASSERT(atomic_read(&imp->imp_replay_inflight) == 0); | |
1228 | atomic_inc(&imp->imp_replay_inflight); | |
1229 | ||
1230 | req = ptlrpc_request_alloc_pack(imp, &RQF_OBD_PING, LUSTRE_OBD_VERSION, | |
1231 | OBD_PING); | |
1232 | if (req == NULL) { | |
1233 | atomic_dec(&imp->imp_replay_inflight); | |
0a3bdb00 | 1234 | return -ENOMEM; |
d7e09d03 PT |
1235 | } |
1236 | ||
1237 | ptlrpc_request_set_replen(req); | |
1238 | req->rq_send_state = LUSTRE_IMP_REPLAY_WAIT; | |
1239 | lustre_msg_add_flags(req->rq_reqmsg, | |
1240 | MSG_LOCK_REPLAY_DONE | MSG_REQ_REPLAY_DONE); | |
1241 | if (AT_OFF) | |
1242 | req->rq_timeout *= 3; | |
1243 | req->rq_interpret_reply = completed_replay_interpret; | |
1244 | ||
1245 | ptlrpcd_add_req(req, PDL_POLICY_ROUND, -1); | |
0a3bdb00 | 1246 | return 0; |
d7e09d03 PT |
1247 | } |
1248 | ||
1249 | /** | |
1250 | * In kernel code all import invalidation happens in its own | |
1251 | * separate thread, so that whatever application happened to encounter | |
1252 | * a problem could still be killed or otherwise continue | |
1253 | */ | |
1254 | static int ptlrpc_invalidate_import_thread(void *data) | |
1255 | { | |
1256 | struct obd_import *imp = data; | |
1257 | ||
d7e09d03 PT |
1258 | unshare_fs_struct(); |
1259 | ||
1260 | CDEBUG(D_HA, "thread invalidate import %s to %s@%s\n", | |
1261 | imp->imp_obd->obd_name, obd2cli_tgt(imp->imp_obd), | |
1262 | imp->imp_connection->c_remote_uuid.uuid); | |
1263 | ||
1264 | ptlrpc_invalidate_import(imp); | |
1265 | ||
1266 | if (obd_dump_on_eviction) { | |
1267 | CERROR("dump the log upon eviction\n"); | |
1268 | libcfs_debug_dumplog(); | |
1269 | } | |
1270 | ||
1271 | IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER); | |
1272 | ptlrpc_import_recovery_state_machine(imp); | |
1273 | ||
1274 | class_import_put(imp); | |
0a3bdb00 | 1275 | return 0; |
d7e09d03 PT |
1276 | } |
1277 | ||
1278 | /** | |
1279 | * This is the state machine for client-side recovery on import. | |
1280 | * | |
b6da17f3 | 1281 | * Typically we have two possibly paths. If we came to server and it is not |
d7e09d03 PT |
1282 | * in recovery, we just enter IMP_EVICTED state, invalidate our import |
1283 | * state and reconnect from scratch. | |
1284 | * If we came to server that is in recovery, we enter IMP_REPLAY import state. | |
1285 | * We go through our list of requests to replay and send them to server one by | |
1286 | * one. | |
1287 | * After sending all request from the list we change import state to | |
1288 | * IMP_REPLAY_LOCKS and re-request all the locks we believe we have from server | |
1289 | * and also all the locks we don't yet have and wait for server to grant us. | |
1290 | * After that we send a special "replay completed" request and change import | |
1291 | * state to IMP_REPLAY_WAIT. | |
1292 | * Upon receiving reply to that "replay completed" RPC we enter IMP_RECOVER | |
1293 | * state and resend all requests from sending list. | |
1294 | * After that we promote import to FULL state and send all delayed requests | |
1295 | * and import is fully operational after that. | |
1296 | * | |
1297 | */ | |
1298 | int ptlrpc_import_recovery_state_machine(struct obd_import *imp) | |
1299 | { | |
1300 | int rc = 0; | |
1301 | int inflight; | |
1302 | char *target_start; | |
1303 | int target_len; | |
1304 | ||
d7e09d03 PT |
1305 | if (imp->imp_state == LUSTRE_IMP_EVICTED) { |
1306 | deuuidify(obd2cli_tgt(imp->imp_obd), NULL, | |
1307 | &target_start, &target_len); | |
1308 | /* Don't care about MGC eviction */ | |
1309 | if (strcmp(imp->imp_obd->obd_type->typ_name, | |
1310 | LUSTRE_MGC_NAME) != 0) { | |
1311 | LCONSOLE_ERROR_MSG(0x167, "%s: This client was evicted " | |
1312 | "by %.*s; in progress operations " | |
1313 | "using this service will fail.\n", | |
1314 | imp->imp_obd->obd_name, target_len, | |
1315 | target_start); | |
1316 | } | |
1317 | CDEBUG(D_HA, "evicted from %s@%s; invalidating\n", | |
1318 | obd2cli_tgt(imp->imp_obd), | |
1319 | imp->imp_connection->c_remote_uuid.uuid); | |
1320 | /* reset vbr_failed flag upon eviction */ | |
1321 | spin_lock(&imp->imp_lock); | |
1322 | imp->imp_vbr_failed = 0; | |
1323 | spin_unlock(&imp->imp_lock); | |
1324 | ||
1325 | { | |
68b636b6 | 1326 | struct task_struct *task; |
d7e09d03 PT |
1327 | /* bug 17802: XXX client_disconnect_export vs connect request |
1328 | * race. if client will evicted at this time, we start | |
1329 | * invalidate thread without reference to import and import can | |
1330 | * be freed at same time. */ | |
1331 | class_import_get(imp); | |
1332 | task = kthread_run(ptlrpc_invalidate_import_thread, imp, | |
1333 | "ll_imp_inval"); | |
1334 | if (IS_ERR(task)) { | |
1335 | class_import_put(imp); | |
1336 | CERROR("error starting invalidate thread: %d\n", rc); | |
1337 | rc = PTR_ERR(task); | |
1338 | } else { | |
1339 | rc = 0; | |
1340 | } | |
0a3bdb00 | 1341 | return rc; |
d7e09d03 PT |
1342 | } |
1343 | } | |
1344 | ||
1345 | if (imp->imp_state == LUSTRE_IMP_REPLAY) { | |
1346 | CDEBUG(D_HA, "replay requested by %s\n", | |
1347 | obd2cli_tgt(imp->imp_obd)); | |
1348 | rc = ptlrpc_replay_next(imp, &inflight); | |
1349 | if (inflight == 0 && | |
1350 | atomic_read(&imp->imp_replay_inflight) == 0) { | |
1351 | IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY_LOCKS); | |
1352 | rc = ldlm_replay_locks(imp); | |
1353 | if (rc) | |
1354 | GOTO(out, rc); | |
1355 | } | |
1356 | rc = 0; | |
1357 | } | |
1358 | ||
1359 | if (imp->imp_state == LUSTRE_IMP_REPLAY_LOCKS) { | |
1360 | if (atomic_read(&imp->imp_replay_inflight) == 0) { | |
1361 | IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY_WAIT); | |
1362 | rc = signal_completed_replay(imp); | |
1363 | if (rc) | |
1364 | GOTO(out, rc); | |
1365 | } | |
1366 | ||
1367 | } | |
1368 | ||
1369 | if (imp->imp_state == LUSTRE_IMP_REPLAY_WAIT) { | |
1370 | if (atomic_read(&imp->imp_replay_inflight) == 0) { | |
1371 | IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER); | |
1372 | } | |
1373 | } | |
1374 | ||
1375 | if (imp->imp_state == LUSTRE_IMP_RECOVER) { | |
1376 | CDEBUG(D_HA, "reconnected to %s@%s\n", | |
1377 | obd2cli_tgt(imp->imp_obd), | |
1378 | imp->imp_connection->c_remote_uuid.uuid); | |
1379 | ||
1380 | rc = ptlrpc_resend(imp); | |
1381 | if (rc) | |
1382 | GOTO(out, rc); | |
1383 | IMPORT_SET_STATE(imp, LUSTRE_IMP_FULL); | |
1384 | ptlrpc_activate_import(imp); | |
1385 | ||
1386 | deuuidify(obd2cli_tgt(imp->imp_obd), NULL, | |
1387 | &target_start, &target_len); | |
1388 | LCONSOLE_INFO("%s: Connection restored to %.*s (at %s)\n", | |
1389 | imp->imp_obd->obd_name, | |
1390 | target_len, target_start, | |
1391 | libcfs_nid2str(imp->imp_connection->c_peer.nid)); | |
1392 | } | |
1393 | ||
1394 | if (imp->imp_state == LUSTRE_IMP_FULL) { | |
1395 | wake_up_all(&imp->imp_recovery_waitq); | |
1396 | ptlrpc_wake_delayed(imp); | |
1397 | } | |
1398 | ||
1399 | out: | |
0a3bdb00 | 1400 | return rc; |
d7e09d03 PT |
1401 | } |
1402 | ||
1403 | int ptlrpc_disconnect_import(struct obd_import *imp, int noclose) | |
1404 | { | |
1405 | struct ptlrpc_request *req; | |
1406 | int rq_opc, rc = 0; | |
d7e09d03 | 1407 | |
88291a7a | 1408 | if (imp->imp_obd->obd_force) |
d7e09d03 PT |
1409 | GOTO(set_state, rc); |
1410 | ||
1411 | switch (imp->imp_connect_op) { | |
88291a7a AD |
1412 | case OST_CONNECT: |
1413 | rq_opc = OST_DISCONNECT; | |
1414 | break; | |
1415 | case MDS_CONNECT: | |
1416 | rq_opc = MDS_DISCONNECT; | |
1417 | break; | |
1418 | case MGS_CONNECT: | |
1419 | rq_opc = MGS_DISCONNECT; | |
1420 | break; | |
d7e09d03 | 1421 | default: |
88291a7a AD |
1422 | rc = -EINVAL; |
1423 | CERROR("%s: don't know how to disconnect from %s " | |
1424 | "(connect_op %d): rc = %d\n", | |
1425 | imp->imp_obd->obd_name, obd2cli_tgt(imp->imp_obd), | |
1426 | imp->imp_connect_op, rc); | |
1427 | return rc; | |
d7e09d03 PT |
1428 | } |
1429 | ||
1430 | if (ptlrpc_import_in_recovery(imp)) { | |
1431 | struct l_wait_info lwi; | |
1432 | cfs_duration_t timeout; | |
1433 | ||
d7e09d03 PT |
1434 | if (AT_OFF) { |
1435 | if (imp->imp_server_timeout) | |
1436 | timeout = cfs_time_seconds(obd_timeout / 2); | |
1437 | else | |
1438 | timeout = cfs_time_seconds(obd_timeout); | |
1439 | } else { | |
1440 | int idx = import_at_get_index(imp, | |
1441 | imp->imp_client->cli_request_portal); | |
1442 | timeout = cfs_time_seconds( | |
1443 | at_get(&imp->imp_at.iat_service_estimate[idx])); | |
1444 | } | |
1445 | ||
1446 | lwi = LWI_TIMEOUT_INTR(cfs_timeout_cap(timeout), | |
1447 | back_to_sleep, LWI_ON_SIGNAL_NOOP, NULL); | |
1448 | rc = l_wait_event(imp->imp_recovery_waitq, | |
1449 | !ptlrpc_import_in_recovery(imp), &lwi); | |
1450 | ||
1451 | } | |
1452 | ||
1453 | spin_lock(&imp->imp_lock); | |
1454 | if (imp->imp_state != LUSTRE_IMP_FULL) | |
1455 | GOTO(out, 0); | |
d7e09d03 PT |
1456 | spin_unlock(&imp->imp_lock); |
1457 | ||
1458 | req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_DISCONNECT, | |
1459 | LUSTRE_OBD_VERSION, rq_opc); | |
1460 | if (req) { | |
1461 | /* We are disconnecting, do not retry a failed DISCONNECT rpc if | |
1462 | * it fails. We can get through the above with a down server | |
1463 | * if the client doesn't know the server is gone yet. */ | |
1464 | req->rq_no_resend = 1; | |
1465 | ||
1466 | /* We want client umounts to happen quickly, no matter the | |
1467 | server state... */ | |
1468 | req->rq_timeout = min_t(int, req->rq_timeout, | |
1469 | INITIAL_CONNECT_TIMEOUT); | |
1470 | ||
1471 | IMPORT_SET_STATE(imp, LUSTRE_IMP_CONNECTING); | |
1472 | req->rq_send_state = LUSTRE_IMP_CONNECTING; | |
1473 | ptlrpc_request_set_replen(req); | |
1474 | rc = ptlrpc_queue_wait(req); | |
1475 | ptlrpc_req_finished(req); | |
1476 | } | |
1477 | ||
1478 | set_state: | |
1479 | spin_lock(&imp->imp_lock); | |
1480 | out: | |
1481 | if (noclose) | |
1482 | IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_DISCON); | |
1483 | else | |
1484 | IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_CLOSED); | |
1485 | memset(&imp->imp_remote_handle, 0, sizeof(imp->imp_remote_handle)); | |
1486 | spin_unlock(&imp->imp_lock); | |
1487 | ||
88291a7a AD |
1488 | if (rc == -ETIMEDOUT || rc == -ENOTCONN || rc == -ESHUTDOWN) |
1489 | rc = 0; | |
1490 | ||
0a3bdb00 | 1491 | return rc; |
d7e09d03 PT |
1492 | } |
1493 | EXPORT_SYMBOL(ptlrpc_disconnect_import); | |
1494 | ||
1495 | void ptlrpc_cleanup_imp(struct obd_import *imp) | |
1496 | { | |
d7e09d03 PT |
1497 | spin_lock(&imp->imp_lock); |
1498 | IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_CLOSED); | |
1499 | imp->imp_generation++; | |
1500 | spin_unlock(&imp->imp_lock); | |
1501 | ptlrpc_abort_inflight(imp); | |
d7e09d03 PT |
1502 | } |
1503 | EXPORT_SYMBOL(ptlrpc_cleanup_imp); | |
1504 | ||
1505 | /* Adaptive Timeout utils */ | |
1506 | extern unsigned int at_min, at_max, at_history; | |
1507 | ||
1508 | /* Bin into timeslices using AT_BINS bins. | |
1509 | This gives us a max of the last binlimit*AT_BINS secs without the storage, | |
1510 | but still smoothing out a return to normalcy from a slow response. | |
1511 | (E.g. remember the maximum latency in each minute of the last 4 minutes.) */ | |
1512 | int at_measured(struct adaptive_timeout *at, unsigned int val) | |
1513 | { | |
1514 | unsigned int old = at->at_current; | |
1515 | time_t now = cfs_time_current_sec(); | |
1516 | time_t binlimit = max_t(time_t, at_history / AT_BINS, 1); | |
1517 | ||
1518 | LASSERT(at); | |
1519 | CDEBUG(D_OTHER, "add %u to %p time=%lu v=%u (%u %u %u %u)\n", | |
1520 | val, at, now - at->at_binstart, at->at_current, | |
1521 | at->at_hist[0], at->at_hist[1], at->at_hist[2], at->at_hist[3]); | |
1522 | ||
1523 | if (val == 0) | |
1524 | /* 0's don't count, because we never want our timeout to | |
1525 | drop to 0, and because 0 could mean an error */ | |
1526 | return 0; | |
1527 | ||
1528 | spin_lock(&at->at_lock); | |
1529 | ||
1530 | if (unlikely(at->at_binstart == 0)) { | |
1531 | /* Special case to remove default from history */ | |
1532 | at->at_current = val; | |
1533 | at->at_worst_ever = val; | |
1534 | at->at_worst_time = now; | |
1535 | at->at_hist[0] = val; | |
1536 | at->at_binstart = now; | |
3949015e | 1537 | } else if (now - at->at_binstart < binlimit) { |
d7e09d03 PT |
1538 | /* in bin 0 */ |
1539 | at->at_hist[0] = max(val, at->at_hist[0]); | |
1540 | at->at_current = max(val, at->at_current); | |
1541 | } else { | |
1542 | int i, shift; | |
1543 | unsigned int maxv = val; | |
1544 | /* move bins over */ | |
1545 | shift = (now - at->at_binstart) / binlimit; | |
1546 | LASSERT(shift > 0); | |
3949015e | 1547 | for (i = AT_BINS - 1; i >= 0; i--) { |
d7e09d03 PT |
1548 | if (i >= shift) { |
1549 | at->at_hist[i] = at->at_hist[i - shift]; | |
1550 | maxv = max(maxv, at->at_hist[i]); | |
1551 | } else { | |
1552 | at->at_hist[i] = 0; | |
1553 | } | |
1554 | } | |
1555 | at->at_hist[0] = val; | |
1556 | at->at_current = maxv; | |
1557 | at->at_binstart += shift * binlimit; | |
1558 | } | |
1559 | ||
1560 | if (at->at_current > at->at_worst_ever) { | |
1561 | at->at_worst_ever = at->at_current; | |
1562 | at->at_worst_time = now; | |
1563 | } | |
1564 | ||
1565 | if (at->at_flags & AT_FLG_NOHIST) | |
1566 | /* Only keep last reported val; keeping the rest of the history | |
1567 | for proc only */ | |
1568 | at->at_current = val; | |
1569 | ||
1570 | if (at_max > 0) | |
1571 | at->at_current = min(at->at_current, at_max); | |
1572 | at->at_current = max(at->at_current, at_min); | |
1573 | ||
1574 | if (at->at_current != old) | |
1575 | CDEBUG(D_OTHER, "AT %p change: old=%u new=%u delta=%d " | |
1576 | "(val=%u) hist %u %u %u %u\n", at, | |
1577 | old, at->at_current, at->at_current - old, val, | |
1578 | at->at_hist[0], at->at_hist[1], at->at_hist[2], | |
1579 | at->at_hist[3]); | |
1580 | ||
1581 | /* if we changed, report the old value */ | |
1582 | old = (at->at_current != old) ? old : 0; | |
1583 | ||
1584 | spin_unlock(&at->at_lock); | |
1585 | return old; | |
1586 | } | |
1587 | ||
1588 | /* Find the imp_at index for a given portal; assign if space available */ | |
1589 | int import_at_get_index(struct obd_import *imp, int portal) | |
1590 | { | |
1591 | struct imp_at *at = &imp->imp_at; | |
1592 | int i; | |
1593 | ||
1594 | for (i = 0; i < IMP_AT_MAX_PORTALS; i++) { | |
1595 | if (at->iat_portal[i] == portal) | |
1596 | return i; | |
1597 | if (at->iat_portal[i] == 0) | |
1598 | /* unused */ | |
1599 | break; | |
1600 | } | |
1601 | ||
1602 | /* Not found in list, add it under a lock */ | |
1603 | spin_lock(&imp->imp_lock); | |
1604 | ||
1605 | /* Check unused under lock */ | |
1606 | for (; i < IMP_AT_MAX_PORTALS; i++) { | |
1607 | if (at->iat_portal[i] == portal) | |
1608 | goto out; | |
1609 | if (at->iat_portal[i] == 0) | |
1610 | /* unused */ | |
1611 | break; | |
1612 | } | |
1613 | ||
1614 | /* Not enough portals? */ | |
1615 | LASSERT(i < IMP_AT_MAX_PORTALS); | |
1616 | ||
1617 | at->iat_portal[i] = portal; | |
1618 | out: | |
1619 | spin_unlock(&imp->imp_lock); | |
1620 | return i; | |
1621 | } |