1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/ptlrpc/import.c
38 * Author: Mike Shaver <shaver@clusterfs.com>
41 #define DEBUG_SUBSYSTEM S_RPC
43 # include <liblustre.h>
46 #include <obd_support.h>
47 #include <lustre_ha.h>
48 #include <lustre_net.h>
49 #include <lustre_import.h>
50 #include <lustre_export.h>
52 #include <obd_cksum.h>
53 #include <obd_class.h>
55 #include "ptlrpc_internal.h"
57 struct ptlrpc_connect_async_args {
58 __u64 pcaa_peer_committed;
59 int pcaa_initial_connect;
62 static void __import_set_state(struct obd_import *imp,
63 enum lustre_imp_state state)
65 imp->imp_state = state;
66 imp->imp_state_hist[imp->imp_state_hist_idx].ish_state = state;
67 imp->imp_state_hist[imp->imp_state_hist_idx].ish_time =
68 cfs_time_current_sec();
69 imp->imp_state_hist_idx = (imp->imp_state_hist_idx + 1) %
73 /* A CLOSED import should remain so. */
74 #define IMPORT_SET_STATE_NOLOCK(imp, state) \
76 if (imp->imp_state != LUSTRE_IMP_CLOSED) { \
77 CDEBUG(D_HA, "%p %s: changing import state from %s to %s\n", \
78 imp, obd2cli_tgt(imp->imp_obd), \
79 ptlrpc_import_state_name(imp->imp_state), \
80 ptlrpc_import_state_name(state)); \
81 __import_set_state(imp, state); \
85 #define IMPORT_SET_STATE(imp, state) \
87 spin_lock(&imp->imp_lock); \
88 IMPORT_SET_STATE_NOLOCK(imp, state); \
89 spin_unlock(&imp->imp_lock); \
93 static int ptlrpc_connect_interpret(const struct lu_env *env,
94 struct ptlrpc_request *request,
96 int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
98 /* Only this function is allowed to change the import state when it is
99 * CLOSED. I would rather refcount the import and free it after
100 * disconnection like we do with exports. To do that, the client_obd
101 * will need to save the peer info somewhere other than in the import,
103 int ptlrpc_init_import(struct obd_import *imp)
105 spin_lock(&imp->imp_lock);
107 imp->imp_generation++;
108 imp->imp_state = LUSTRE_IMP_NEW;
110 spin_unlock(&imp->imp_lock);
114 EXPORT_SYMBOL(ptlrpc_init_import);
116 #define UUID_STR "_UUID"
117 static void deuuidify(char *uuid, const char *prefix, char **uuid_start,
120 *uuid_start = !prefix || strncmp(uuid, prefix, strlen(prefix))
121 ? uuid : uuid + strlen(prefix);
123 *uuid_len = strlen(*uuid_start);
125 if (*uuid_len < strlen(UUID_STR))
128 if (!strncmp(*uuid_start + *uuid_len - strlen(UUID_STR),
129 UUID_STR, strlen(UUID_STR)))
130 *uuid_len -= strlen(UUID_STR);
133 /* Returns true if import was FULL, false if import was already not
135 * @imp - import to be disconnected
136 * @conn_cnt - connection count (epoch) of the request that timed out
137 * and caused the disconnection. In some cases, multiple
138 * inflight requests can fail to a single target (e.g. OST
139 * bulk requests) and if one has already caused a reconnection
140 * (increasing the import->conn_cnt) the older failure should
141 * not also cause a reconnection. If zero it forces a reconnect.
143 int ptlrpc_set_import_discon(struct obd_import *imp, __u32 conn_cnt)
147 spin_lock(&imp->imp_lock);
149 if (imp->imp_state == LUSTRE_IMP_FULL &&
150 (conn_cnt == 0 || conn_cnt == imp->imp_conn_cnt)) {
154 deuuidify(obd2cli_tgt(imp->imp_obd), NULL,
155 &target_start, &target_len);
157 if (imp->imp_replayable) {
158 LCONSOLE_WARN("%s: Connection to service %.*s via nid "
159 "%s was lost; in progress operations using this "
160 "service will wait for recovery to complete.\n",
161 imp->imp_obd->obd_name, target_len, target_start,
162 libcfs_nid2str(imp->imp_connection->c_peer.nid));
164 LCONSOLE_ERROR_MSG(0x166, "%s: Connection to service "
165 "%.*s via nid %s was lost; in progress "
166 "operations using this service will fail.\n",
167 imp->imp_obd->obd_name,
168 target_len, target_start,
169 libcfs_nid2str(imp->imp_connection->c_peer.nid));
171 ptlrpc_deactivate_timeouts(imp);
172 IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_DISCON);
173 spin_unlock(&imp->imp_lock);
175 if (obd_dump_on_timeout)
176 libcfs_debug_dumplog();
178 obd_import_event(imp->imp_obd, imp, IMP_EVENT_DISCON);
181 spin_unlock(&imp->imp_lock);
182 CDEBUG(D_HA, "%s: import %p already %s (conn %u, was %u): %s\n",
183 imp->imp_client->cli_name, imp,
184 (imp->imp_state == LUSTRE_IMP_FULL &&
185 imp->imp_conn_cnt > conn_cnt) ?
186 "reconnected" : "not connected", imp->imp_conn_cnt,
187 conn_cnt, ptlrpc_import_state_name(imp->imp_state));
193 /* Must be called with imp_lock held! */
194 static void ptlrpc_deactivate_and_unlock_import(struct obd_import *imp)
197 LASSERT_SPIN_LOCKED(&imp->imp_lock);
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);
204 ptlrpc_abort_inflight(imp);
205 obd_import_event(imp->imp_obd, imp, IMP_EVENT_INACTIVE);
211 * This acts as a barrier; all existing requests are rejected, and
212 * no new requests will be accepted until the import is valid again.
214 void ptlrpc_deactivate_import(struct obd_import *imp)
216 spin_lock(&imp->imp_lock);
217 ptlrpc_deactivate_and_unlock_import(imp);
221 ptlrpc_inflight_deadline(struct ptlrpc_request *req, time_t now)
225 if (!(((req->rq_phase == RQ_PHASE_RPC) && !req->rq_waiting) ||
226 (req->rq_phase == RQ_PHASE_BULK) ||
227 (req->rq_phase == RQ_PHASE_NEW)))
230 if (req->rq_timedout)
233 if (req->rq_phase == RQ_PHASE_NEW)
236 dl = req->rq_deadline;
244 static unsigned int ptlrpc_inflight_timeout(struct obd_import *imp)
246 time_t now = cfs_time_current_sec();
247 struct list_head *tmp, *n;
248 struct ptlrpc_request *req;
249 unsigned int timeout = 0;
251 spin_lock(&imp->imp_lock);
252 list_for_each_safe(tmp, n, &imp->imp_sending_list) {
253 req = list_entry(tmp, struct ptlrpc_request, rq_list);
254 timeout = max(ptlrpc_inflight_deadline(req, now), timeout);
256 spin_unlock(&imp->imp_lock);
261 * This function will invalidate the import, if necessary, then block
262 * for all the RPC completions, and finally notify the obd to
263 * invalidate its state (ie cancel locks, clear pending requests,
266 void ptlrpc_invalidate_import(struct obd_import *imp)
268 struct list_head *tmp, *n;
269 struct ptlrpc_request *req;
270 struct l_wait_info lwi;
271 unsigned int timeout;
274 atomic_inc(&imp->imp_inval_count);
277 * If this is an invalid MGC connection, then don't bother
278 * waiting for imp_inflight to drop to 0.
280 if (imp->imp_invalid && imp->imp_recon_bk &&!imp->imp_obd->obd_no_recov)
283 if (!imp->imp_invalid || imp->imp_obd->obd_no_recov)
284 ptlrpc_deactivate_import(imp);
286 LASSERT(imp->imp_invalid);
288 /* Wait forever until inflight == 0. We really can't do it another
289 * way because in some cases we need to wait for very long reply
290 * unlink. We can't do anything before that because there is really
291 * no guarantee that some rdma transfer is not in progress right now. */
293 /* Calculate max timeout for waiting on rpcs to error
294 * out. Use obd_timeout if calculated value is smaller
296 timeout = ptlrpc_inflight_timeout(imp);
297 timeout += timeout / 3;
300 timeout = obd_timeout;
302 CDEBUG(D_RPCTRACE,"Sleeping %d sec for inflight to error out\n",
305 /* Wait for all requests to error out and call completion
306 * callbacks. Cap it at obd_timeout -- these should all
307 * have been locally cancelled by ptlrpc_abort_inflight. */
308 lwi = LWI_TIMEOUT_INTERVAL(
309 cfs_timeout_cap(cfs_time_seconds(timeout)),
310 cfs_time_seconds(1), NULL, NULL);
311 rc = l_wait_event(imp->imp_recovery_waitq,
312 (atomic_read(&imp->imp_inflight) == 0), &lwi);
314 const char *cli_tgt = obd2cli_tgt(imp->imp_obd);
316 CERROR("%s: rc = %d waiting for callback (%d != 0)\n",
317 cli_tgt, rc, atomic_read(&imp->imp_inflight));
319 spin_lock(&imp->imp_lock);
320 list_for_each_safe(tmp, n, &imp->imp_sending_list) {
321 req = list_entry(tmp, struct ptlrpc_request,
323 DEBUG_REQ(D_ERROR, req,"still on sending list");
325 list_for_each_safe(tmp, n, &imp->imp_delayed_list) {
326 req = list_entry(tmp, struct ptlrpc_request,
328 DEBUG_REQ(D_ERROR, req,"still on delayed list");
331 if (atomic_read(&imp->imp_unregistering) == 0) {
332 /* We know that only "unregistering" rpcs may
333 * still survive in sending or delaying lists
334 * (They are waiting for long reply unlink in
335 * sluggish nets). Let's check this. If there
336 * is no unregistering and inflight != 0 this
338 LASSERT(atomic_read(&imp->imp_inflight) == 0);
340 /* Let's save one loop as soon as inflight have
341 * dropped to zero. No new inflights possible at
345 CERROR("%s: RPCs in \"%s\" phase found (%d). "
346 "Network is sluggish? Waiting them "
347 "to error out.\n", cli_tgt,
348 ptlrpc_phase2str(RQ_PHASE_UNREGISTERING),
349 atomic_read(&imp->imp_unregistering));
351 spin_unlock(&imp->imp_lock);
356 * Let's additionally check that no new rpcs added to import in
357 * "invalidate" state.
359 LASSERT(atomic_read(&imp->imp_inflight) == 0);
361 obd_import_event(imp->imp_obd, imp, IMP_EVENT_INVALIDATE);
362 sptlrpc_import_flush_all_ctx(imp);
364 atomic_dec(&imp->imp_inval_count);
365 cfs_waitq_broadcast(&imp->imp_recovery_waitq);
368 /* unset imp_invalid */
369 void ptlrpc_activate_import(struct obd_import *imp)
371 struct obd_device *obd = imp->imp_obd;
373 spin_lock(&imp->imp_lock);
374 imp->imp_invalid = 0;
375 ptlrpc_activate_timeouts(imp);
376 spin_unlock(&imp->imp_lock);
377 obd_import_event(obd, imp, IMP_EVENT_ACTIVE);
380 void ptlrpc_fail_import(struct obd_import *imp, __u32 conn_cnt)
384 LASSERT(!imp->imp_dlm_fake);
386 if (ptlrpc_set_import_discon(imp, conn_cnt)) {
387 if (!imp->imp_replayable) {
388 CDEBUG(D_HA, "import %s@%s for %s not replayable, "
389 "auto-deactivating\n",
390 obd2cli_tgt(imp->imp_obd),
391 imp->imp_connection->c_remote_uuid.uuid,
392 imp->imp_obd->obd_name);
393 ptlrpc_deactivate_import(imp);
396 CDEBUG(D_HA, "%s: waking up pinger\n",
397 obd2cli_tgt(imp->imp_obd));
399 spin_lock(&imp->imp_lock);
400 imp->imp_force_verify = 1;
401 spin_unlock(&imp->imp_lock);
403 ptlrpc_pinger_wake_up();
408 int ptlrpc_reconnect_import(struct obd_import *imp)
410 ptlrpc_set_import_discon(imp, 0);
411 /* Force a new connect attempt */
412 ptlrpc_invalidate_import(imp);
413 /* Do a fresh connect next time by zeroing the handle */
414 ptlrpc_disconnect_import(imp, 1);
415 /* Wait for all invalidate calls to finish */
416 if (atomic_read(&imp->imp_inval_count) > 0) {
418 struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
419 rc = l_wait_event(imp->imp_recovery_waitq,
420 (atomic_read(&imp->imp_inval_count) == 0),
423 CERROR("Interrupted, inval=%d\n",
424 atomic_read(&imp->imp_inval_count));
427 /* Allow reconnect attempts */
428 imp->imp_obd->obd_no_recov = 0;
429 /* Remove 'invalid' flag */
430 ptlrpc_activate_import(imp);
431 /* Attempt a new connect */
432 ptlrpc_recover_import(imp, NULL);
436 EXPORT_SYMBOL(ptlrpc_reconnect_import);
438 static int import_select_connection(struct obd_import *imp)
440 struct obd_import_conn *imp_conn = NULL, *conn;
441 struct obd_export *dlmexp;
445 spin_lock(&imp->imp_lock);
447 if (list_empty(&imp->imp_conn_list)) {
448 CERROR("%s: no connections available\n",
449 imp->imp_obd->obd_name);
450 spin_unlock(&imp->imp_lock);
454 list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
455 CDEBUG(D_HA, "%s: connect to NID %s last attempt "LPU64"\n",
456 imp->imp_obd->obd_name,
457 libcfs_nid2str(conn->oic_conn->c_peer.nid),
458 conn->oic_last_attempt);
459 /* Don't thrash connections */
460 if (cfs_time_before_64(cfs_time_current_64(),
461 conn->oic_last_attempt +
462 cfs_time_seconds(CONNECTION_SWITCH_MIN))) {
466 /* If we have not tried this connection since the
467 the last successful attempt, go with this one */
468 if ((conn->oic_last_attempt == 0) ||
469 cfs_time_beforeq_64(conn->oic_last_attempt,
470 imp->imp_last_success_conn)) {
476 /* If all of the connections have already been tried
477 since the last successful connection; just choose the
478 least recently used */
481 else if (cfs_time_before_64(conn->oic_last_attempt,
482 imp_conn->oic_last_attempt))
486 /* if not found, simply choose the current one */
488 LASSERT(imp->imp_conn_current);
489 imp_conn = imp->imp_conn_current;
492 LASSERT(imp_conn->oic_conn);
494 /* If we've tried everything, and we're back to the beginning of the
495 list, increase our timeout and try again. It will be reset when
496 we do finally connect. (FIXME: really we should wait for all network
497 state associated with the last connection attempt to drain before
498 trying to reconnect on it.) */
499 if (tried_all && (imp->imp_conn_list.next == &imp_conn->oic_item) &&
500 !imp->imp_recon_bk /* not retrying */) {
501 if (at_get(&imp->imp_at.iat_net_latency) <
502 CONNECTION_SWITCH_MAX) {
503 at_add(&imp->imp_at.iat_net_latency,
504 at_get(&imp->imp_at.iat_net_latency) +
505 CONNECTION_SWITCH_INC);
507 LASSERT(imp_conn->oic_last_attempt);
508 CWARN("%s: tried all connections, increasing latency to %ds\n",
509 imp->imp_obd->obd_name,
510 at_get(&imp->imp_at.iat_net_latency));
513 imp_conn->oic_last_attempt = cfs_time_current_64();
515 /* switch connection, don't mind if it's same as the current one */
516 if (imp->imp_connection)
517 ptlrpc_connection_put(imp->imp_connection);
518 imp->imp_connection = ptlrpc_connection_addref(imp_conn->oic_conn);
520 dlmexp = class_conn2export(&imp->imp_dlm_handle);
521 LASSERT(dlmexp != NULL);
522 if (dlmexp->exp_connection)
523 ptlrpc_connection_put(dlmexp->exp_connection);
524 dlmexp->exp_connection = ptlrpc_connection_addref(imp_conn->oic_conn);
525 class_export_put(dlmexp);
527 if (imp->imp_conn_current != imp_conn) {
528 if (imp->imp_conn_current)
529 LCONSOLE_INFO("Changing connection for %s to %s/%s\n",
530 imp->imp_obd->obd_name,
531 imp_conn->oic_uuid.uuid,
532 libcfs_nid2str(imp_conn->oic_conn->c_peer.nid));
533 imp->imp_conn_current = imp_conn;
536 CDEBUG(D_HA, "%s: import %p using connection %s/%s\n",
537 imp->imp_obd->obd_name, imp, imp_conn->oic_uuid.uuid,
538 libcfs_nid2str(imp_conn->oic_conn->c_peer.nid));
540 spin_unlock(&imp->imp_lock);
546 * must be called under imp_lock
548 static int ptlrpc_first_transno(struct obd_import *imp, __u64 *transno)
550 struct ptlrpc_request *req;
551 struct list_head *tmp;
553 if (list_empty(&imp->imp_replay_list))
555 tmp = imp->imp_replay_list.next;
556 req = list_entry(tmp, struct ptlrpc_request, rq_replay_list);
557 *transno = req->rq_transno;
558 if (req->rq_transno == 0) {
559 DEBUG_REQ(D_ERROR, req, "zero transno in replay");
566 int ptlrpc_connect_import(struct obd_import *imp, char *new_uuid)
568 struct obd_device *obd = imp->imp_obd;
569 int initial_connect = 0;
571 __u64 committed_before_reconnect = 0;
572 struct ptlrpc_request *request;
573 char *bufs[] = { NULL,
574 obd2cli_tgt(imp->imp_obd),
576 (char *)&imp->imp_dlm_handle,
577 (char *)&imp->imp_connect_data };
578 struct ptlrpc_connect_async_args *aa;
582 spin_lock(&imp->imp_lock);
583 if (imp->imp_state == LUSTRE_IMP_CLOSED) {
584 spin_unlock(&imp->imp_lock);
585 CERROR("can't connect to a closed import\n");
587 } else if (imp->imp_state == LUSTRE_IMP_FULL) {
588 spin_unlock(&imp->imp_lock);
589 CERROR("already connected\n");
591 } else if (imp->imp_state == LUSTRE_IMP_CONNECTING) {
592 spin_unlock(&imp->imp_lock);
593 CERROR("already connecting\n");
597 IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_CONNECTING);
600 imp->imp_resend_replay = 0;
602 if (!lustre_handle_is_used(&imp->imp_remote_handle))
605 committed_before_reconnect = imp->imp_peer_committed_transno;
607 set_transno = ptlrpc_first_transno(imp,
608 &imp->imp_connect_data.ocd_transno);
609 spin_unlock(&imp->imp_lock);
612 struct obd_uuid uuid;
614 obd_str2uuid(&uuid, new_uuid);
615 rc = import_set_conn_priority(imp, &uuid);
620 rc = import_select_connection(imp);
624 /* last in connection list */
625 if (imp->imp_conn_current->oic_item.next == &imp->imp_conn_list) {
626 if (imp->imp_initial_recov_bk && initial_connect) {
627 CDEBUG(D_HA, "Last connection attempt (%d) for %s\n",
628 imp->imp_conn_cnt, obd2cli_tgt(imp->imp_obd));
629 /* Don't retry if connect fails */
631 obd_set_info_async(obd->obd_self_export,
632 sizeof(KEY_INIT_RECOV),
634 sizeof(rc), &rc, NULL);
636 if (imp->imp_recon_bk) {
637 CDEBUG(D_HA, "Last reconnection attempt (%d) for %s\n",
638 imp->imp_conn_cnt, obd2cli_tgt(imp->imp_obd));
639 spin_lock(&imp->imp_lock);
640 imp->imp_last_recon = 1;
641 spin_unlock(&imp->imp_lock);
645 rc = sptlrpc_import_sec_adapt(imp, NULL, 0);
649 /* Reset connect flags to the originally requested flags, in case
650 * the server is updated on-the-fly we will get the new features. */
651 imp->imp_connect_data.ocd_connect_flags = imp->imp_connect_flags_orig;
652 imp->imp_msghdr_flags &= ~MSGHDR_AT_SUPPORT;
654 rc = obd_reconnect(NULL, imp->imp_obd->obd_self_export, obd,
655 &obd->obd_uuid, &imp->imp_connect_data, NULL);
659 request = ptlrpc_request_alloc(imp, &RQF_MDS_CONNECT);
661 GOTO(out, rc = -ENOMEM);
663 rc = ptlrpc_request_bufs_pack(request, LUSTRE_OBD_VERSION,
664 imp->imp_connect_op, bufs, NULL);
666 ptlrpc_request_free(request);
670 /* Report the rpc service time to the server so that it knows how long
671 * to wait for clients to join recovery */
672 lustre_msg_set_service_time(request->rq_reqmsg,
673 at_timeout2est(request->rq_timeout));
675 /* The amount of time we give the server to process the connect req.
676 * import_select_connection will increase the net latency on
677 * repeated reconnect attempts to cover slow networks.
678 * We override/ignore the server rpc completion estimate here,
679 * which may be large if this is a reconnect attempt */
680 request->rq_timeout = INITIAL_CONNECT_TIMEOUT;
681 lustre_msg_set_timeout(request->rq_reqmsg, request->rq_timeout);
684 lustre_msg_add_op_flags(request->rq_reqmsg, MSG_CONNECT_LIBCLIENT);
686 lustre_msg_add_op_flags(request->rq_reqmsg, MSG_CONNECT_NEXT_VER);
688 request->rq_no_resend = request->rq_no_delay = 1;
689 request->rq_send_state = LUSTRE_IMP_CONNECTING;
690 /* Allow a slightly larger reply for future growth compatibility */
691 req_capsule_set_size(&request->rq_pill, &RMF_CONNECT_DATA, RCL_SERVER,
692 sizeof(struct obd_connect_data)+16*sizeof(__u64));
693 ptlrpc_request_set_replen(request);
694 request->rq_interpret_reply = ptlrpc_connect_interpret;
696 CLASSERT(sizeof (*aa) <= sizeof (request->rq_async_args));
697 aa = ptlrpc_req_async_args(request);
698 memset(aa, 0, sizeof *aa);
700 aa->pcaa_peer_committed = committed_before_reconnect;
701 aa->pcaa_initial_connect = initial_connect;
703 if (aa->pcaa_initial_connect) {
704 spin_lock(&imp->imp_lock);
705 imp->imp_replayable = 1;
706 spin_unlock(&imp->imp_lock);
707 lustre_msg_add_op_flags(request->rq_reqmsg,
708 MSG_CONNECT_INITIAL);
712 lustre_msg_add_op_flags(request->rq_reqmsg,
713 MSG_CONNECT_TRANSNO);
715 DEBUG_REQ(D_RPCTRACE, request, "(re)connect request");
716 ptlrpcd_add_req(request, PSCOPE_OTHER);
720 IMPORT_SET_STATE(imp, LUSTRE_IMP_DISCON);
725 EXPORT_SYMBOL(ptlrpc_connect_import);
727 static void ptlrpc_maybe_ping_import_soon(struct obd_import *imp)
730 struct obd_import_conn *imp_conn;
736 spin_lock(&imp->imp_lock);
737 if (list_empty(&imp->imp_conn_list))
741 imp_conn = list_entry(imp->imp_conn_list.prev,
742 struct obd_import_conn,
745 /* XXX: When the failover node is the primary node, it is possible
746 * to have two identical connections in imp_conn_list. We must
747 * compare not conn's pointers but NIDs, otherwise we can defeat
748 * connection throttling. (See bug 14774.) */
749 if (imp->imp_conn_current->oic_conn->c_peer.nid !=
750 imp_conn->oic_conn->c_peer.nid) {
751 ptlrpc_ping_import_soon(imp);
755 /* liblustre has no pinger thead, so we wakup pinger anyway */
760 spin_unlock(&imp->imp_lock);
763 ptlrpc_pinger_wake_up();
768 static int ptlrpc_connect_interpret(const struct lu_env *env,
769 struct ptlrpc_request *request,
772 struct ptlrpc_connect_async_args *aa = data;
773 struct obd_import *imp = request->rq_import;
774 struct client_obd *cli = &imp->imp_obd->u.cli;
775 struct lustre_handle old_hdl;
776 __u64 old_connect_flags;
780 spin_lock(&imp->imp_lock);
781 if (imp->imp_state == LUSTRE_IMP_CLOSED) {
782 spin_unlock(&imp->imp_lock);
785 spin_unlock(&imp->imp_lock);
790 LASSERT(imp->imp_conn_current);
792 msg_flags = lustre_msg_get_op_flags(request->rq_repmsg);
794 /* All imports are pingable */
795 spin_lock(&imp->imp_lock);
796 imp->imp_pingable = 1;
798 if (aa->pcaa_initial_connect) {
799 if (msg_flags & MSG_CONNECT_REPLAYABLE) {
800 imp->imp_replayable = 1;
801 spin_unlock(&imp->imp_lock);
802 CDEBUG(D_HA, "connected to replayable target: %s\n",
803 obd2cli_tgt(imp->imp_obd));
805 imp->imp_replayable = 0;
806 spin_unlock(&imp->imp_lock);
809 /* if applies, adjust the imp->imp_msg_magic here
810 * according to reply flags */
812 imp->imp_remote_handle =
813 *lustre_msg_get_handle(request->rq_repmsg);
815 /* Initial connects are allowed for clients with non-random
816 * uuids when servers are in recovery. Simply signal the
817 * servers replay is complete and wait in REPLAY_WAIT. */
818 if (msg_flags & MSG_CONNECT_RECOVERING) {
819 CDEBUG(D_HA, "connect to %s during recovery\n",
820 obd2cli_tgt(imp->imp_obd));
821 IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY_LOCKS);
823 IMPORT_SET_STATE(imp, LUSTRE_IMP_FULL);
824 ptlrpc_activate_import(imp);
827 GOTO(finish, rc = 0);
829 spin_unlock(&imp->imp_lock);
832 /* Determine what recovery state to move the import to. */
833 if (MSG_CONNECT_RECONNECT & msg_flags) {
834 memset(&old_hdl, 0, sizeof(old_hdl));
835 if (!memcmp(&old_hdl, lustre_msg_get_handle(request->rq_repmsg),
837 CERROR("%s@%s didn't like our handle "LPX64
838 ", failed\n", obd2cli_tgt(imp->imp_obd),
839 imp->imp_connection->c_remote_uuid.uuid,
840 imp->imp_dlm_handle.cookie);
841 GOTO(out, rc = -ENOTCONN);
844 if (memcmp(&imp->imp_remote_handle,
845 lustre_msg_get_handle(request->rq_repmsg),
846 sizeof(imp->imp_remote_handle))) {
847 int level = msg_flags & MSG_CONNECT_RECOVERING ?
850 /* Bug 16611/14775: if server handle have changed,
851 * that means some sort of disconnection happened.
852 * If the server is not in recovery, that also means it
853 * already erased all of our state because of previous
854 * eviction. If it is in recovery - we are safe to
855 * participate since we can reestablish all of our state
856 * with server again */
857 CDEBUG(level,"%s@%s changed server handle from "
858 LPX64" to "LPX64"%s\n",
859 obd2cli_tgt(imp->imp_obd),
860 imp->imp_connection->c_remote_uuid.uuid,
861 imp->imp_remote_handle.cookie,
862 lustre_msg_get_handle(request->rq_repmsg)->
864 (MSG_CONNECT_RECOVERING & msg_flags) ?
865 " but is still in recovery" : "");
867 imp->imp_remote_handle =
868 *lustre_msg_get_handle(request->rq_repmsg);
870 if (!(MSG_CONNECT_RECOVERING & msg_flags)) {
871 IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED);
872 GOTO(finish, rc = 0);
876 CDEBUG(D_HA, "reconnected to %s@%s after partition\n",
877 obd2cli_tgt(imp->imp_obd),
878 imp->imp_connection->c_remote_uuid.uuid);
881 if (imp->imp_invalid) {
882 CDEBUG(D_HA, "%s: reconnected but import is invalid; "
883 "marking evicted\n", imp->imp_obd->obd_name);
884 IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED);
885 } else if (MSG_CONNECT_RECOVERING & msg_flags) {
886 CDEBUG(D_HA, "%s: reconnected to %s during replay\n",
887 imp->imp_obd->obd_name,
888 obd2cli_tgt(imp->imp_obd));
890 spin_lock(&imp->imp_lock);
891 imp->imp_resend_replay = 1;
892 spin_unlock(&imp->imp_lock);
894 IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY);
896 IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER);
898 } else if ((MSG_CONNECT_RECOVERING & msg_flags) && !imp->imp_invalid) {
899 LASSERT(imp->imp_replayable);
900 imp->imp_remote_handle =
901 *lustre_msg_get_handle(request->rq_repmsg);
902 imp->imp_last_replay_transno = 0;
903 IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY);
905 DEBUG_REQ(D_HA, request, "%s: evicting (reconnect/recover flags"
906 " not set: %x)", imp->imp_obd->obd_name, msg_flags);
907 imp->imp_remote_handle =
908 *lustre_msg_get_handle(request->rq_repmsg);
909 IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED);
912 /* Sanity checks for a reconnected import. */
913 if (!(imp->imp_replayable) != !(msg_flags & MSG_CONNECT_REPLAYABLE)) {
914 CERROR("imp_replayable flag does not match server "
915 "after reconnect. We should LBUG right here.\n");
918 if (lustre_msg_get_last_committed(request->rq_repmsg) <
919 aa->pcaa_peer_committed) {
920 CERROR("%s went back in time (transno "LPD64
921 " was previously committed, server now claims "LPD64
922 ")! See https://bugzilla.lustre.org/show_bug.cgi?"
924 obd2cli_tgt(imp->imp_obd), aa->pcaa_peer_committed,
925 lustre_msg_get_last_committed(request->rq_repmsg));
929 rc = ptlrpc_import_recovery_state_machine(imp);
931 if (rc == -ENOTCONN) {
932 CDEBUG(D_HA, "evicted/aborted by %s@%s during recovery;"
933 "invalidating and reconnecting\n",
934 obd2cli_tgt(imp->imp_obd),
935 imp->imp_connection->c_remote_uuid.uuid);
936 ptlrpc_connect_import(imp, NULL);
940 struct obd_connect_data *ocd;
941 struct obd_export *exp;
943 ret = req_capsule_get_size(&request->rq_pill, &RMF_CONNECT_DATA,
945 /* server replied obd_connect_data is always bigger */
946 ocd = req_capsule_server_sized_get(&request->rq_pill,
947 &RMF_CONNECT_DATA, ret);
949 spin_lock(&imp->imp_lock);
950 list_del(&imp->imp_conn_current->oic_item);
951 list_add(&imp->imp_conn_current->oic_item, &imp->imp_conn_list);
952 imp->imp_last_success_conn =
953 imp->imp_conn_current->oic_last_attempt;
956 spin_unlock(&imp->imp_lock);
957 CERROR("Wrong connect data from server\n");
962 imp->imp_connect_data = *ocd;
964 exp = class_conn2export(&imp->imp_dlm_handle);
965 spin_unlock(&imp->imp_lock);
967 /* check that server granted subset of flags we asked for. */
968 LASSERTF((ocd->ocd_connect_flags &
969 imp->imp_connect_flags_orig) ==
970 ocd->ocd_connect_flags, LPX64" != "LPX64,
971 imp->imp_connect_flags_orig, ocd->ocd_connect_flags);
974 /* This could happen if export is cleaned during the
976 CERROR("Missing export for %s\n",
977 imp->imp_obd->obd_name);
978 GOTO(out, rc = -ENODEV);
980 old_connect_flags = exp->exp_connect_flags;
981 exp->exp_connect_flags = ocd->ocd_connect_flags;
982 imp->imp_obd->obd_self_export->exp_connect_flags =
983 ocd->ocd_connect_flags;
984 class_export_put(exp);
986 obd_import_event(imp->imp_obd, imp, IMP_EVENT_OCD);
988 if (!ocd->ocd_ibits_known &&
989 ocd->ocd_connect_flags & OBD_CONNECT_IBITS)
990 CERROR("Inodebits aware server returned zero compatible"
993 if ((ocd->ocd_connect_flags & OBD_CONNECT_VERSION) &&
994 (ocd->ocd_version > LUSTRE_VERSION_CODE +
995 LUSTRE_VERSION_OFFSET_WARN ||
996 ocd->ocd_version < LUSTRE_VERSION_CODE -
997 LUSTRE_VERSION_OFFSET_WARN)) {
998 /* Sigh, some compilers do not like #ifdef in the middle
999 of macro arguments */
1002 "older. Consider upgrading this client";
1005 "older. Consider recompiling this application";
1007 const char *newer = "newer than client version";
1009 LCONSOLE_WARN("Server %s version (%d.%d.%d.%d) "
1010 "is much %s (%s)\n",
1011 obd2cli_tgt(imp->imp_obd),
1012 OBD_OCD_VERSION_MAJOR(ocd->ocd_version),
1013 OBD_OCD_VERSION_MINOR(ocd->ocd_version),
1014 OBD_OCD_VERSION_PATCH(ocd->ocd_version),
1015 OBD_OCD_VERSION_FIX(ocd->ocd_version),
1016 ocd->ocd_version > LUSTRE_VERSION_CODE ?
1017 newer : older, LUSTRE_VERSION_STRING);
1020 if (ocd->ocd_connect_flags & OBD_CONNECT_CKSUM) {
1021 /* We sent to the server ocd_cksum_types with bits set
1022 * for algorithms we understand. The server masked off
1023 * the checksum types it doesn't support */
1024 if ((ocd->ocd_cksum_types & OBD_CKSUM_ALL) == 0) {
1025 LCONSOLE_WARN("The negotiation of the checksum "
1026 "alogrithm to use with server %s "
1027 "failed (%x/%x), disabling "
1029 obd2cli_tgt(imp->imp_obd),
1030 ocd->ocd_cksum_types,
1032 cli->cl_checksum = 0;
1033 cli->cl_supp_cksum_types = OBD_CKSUM_CRC32;
1034 cli->cl_cksum_type = OBD_CKSUM_CRC32;
1036 cli->cl_supp_cksum_types = ocd->ocd_cksum_types;
1038 if (ocd->ocd_cksum_types & OSC_DEFAULT_CKSUM)
1039 cli->cl_cksum_type = OSC_DEFAULT_CKSUM;
1040 else if (ocd->ocd_cksum_types & OBD_CKSUM_ADLER)
1041 cli->cl_cksum_type = OBD_CKSUM_ADLER;
1043 cli->cl_cksum_type = OBD_CKSUM_CRC32;
1046 /* The server does not support OBD_CONNECT_CKSUM.
1047 * Enforce CRC32 for backward compatibility*/
1048 cli->cl_supp_cksum_types = OBD_CKSUM_CRC32;
1049 cli->cl_cksum_type = OBD_CKSUM_CRC32;
1052 if (ocd->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
1053 cli->cl_max_pages_per_rpc =
1054 ocd->ocd_brw_size >> CFS_PAGE_SHIFT;
1057 /* Reset ns_connect_flags only for initial connect. It might be
1058 * changed in while using FS and if we reset it in reconnect
1059 * this leads to lossing user settings done before such as
1060 * disable lru_resize, etc. */
1061 if (old_connect_flags != exp->exp_connect_flags ||
1062 aa->pcaa_initial_connect) {
1063 CDEBUG(D_HA, "%s: Resetting ns_connect_flags to server "
1064 "flags: "LPX64"\n", imp->imp_obd->obd_name,
1065 ocd->ocd_connect_flags);
1066 imp->imp_obd->obd_namespace->ns_connect_flags =
1067 ocd->ocd_connect_flags;
1068 imp->imp_obd->obd_namespace->ns_orig_connect_flags =
1069 ocd->ocd_connect_flags;
1072 if ((ocd->ocd_connect_flags & OBD_CONNECT_AT) &&
1073 (imp->imp_msg_magic == LUSTRE_MSG_MAGIC_V2))
1074 /* We need a per-message support flag, because
1075 a. we don't know if the incoming connect reply
1076 supports AT or not (in reply_in_callback)
1078 b. failovered server means export and flags are gone
1079 (in ptlrpc_send_reply).
1080 Can only be set when we know AT is supported at
1082 imp->imp_msghdr_flags |= MSGHDR_AT_SUPPORT;
1084 imp->imp_msghdr_flags &= ~MSGHDR_AT_SUPPORT;
1086 LASSERT((cli->cl_max_pages_per_rpc <= PTLRPC_MAX_BRW_PAGES) &&
1087 (cli->cl_max_pages_per_rpc > 0));
1092 IMPORT_SET_STATE(imp, LUSTRE_IMP_DISCON);
1093 spin_lock(&imp->imp_lock);
1094 if (aa->pcaa_initial_connect && !imp->imp_initial_recov &&
1095 (request->rq_import_generation == imp->imp_generation))
1096 ptlrpc_deactivate_and_unlock_import(imp);
1098 spin_unlock(&imp->imp_lock);
1100 if ((imp->imp_recon_bk && imp->imp_last_recon) ||
1103 * Give up trying to reconnect
1104 * EACCES means client has no permission for connection
1106 imp->imp_obd->obd_no_recov = 1;
1107 ptlrpc_deactivate_import(imp);
1110 if (rc == -EPROTO) {
1111 struct obd_connect_data *ocd;
1113 /* reply message might not be ready */
1114 if (request->rq_repmsg == NULL)
1117 ocd = req_capsule_server_get(&request->rq_pill,
1120 (ocd->ocd_connect_flags & OBD_CONNECT_VERSION) &&
1121 (ocd->ocd_version != LUSTRE_VERSION_CODE)) {
1122 /* Actually servers are only supposed to refuse
1123 connection from liblustre clients, so we should
1124 never see this from VFS context */
1125 LCONSOLE_ERROR_MSG(0x16a, "Server %s version "
1127 " refused connection from this client "
1128 "with an incompatible version (%s). "
1129 "Client must be recompiled\n",
1130 obd2cli_tgt(imp->imp_obd),
1131 OBD_OCD_VERSION_MAJOR(ocd->ocd_version),
1132 OBD_OCD_VERSION_MINOR(ocd->ocd_version),
1133 OBD_OCD_VERSION_PATCH(ocd->ocd_version),
1134 OBD_OCD_VERSION_FIX(ocd->ocd_version),
1135 LUSTRE_VERSION_STRING);
1136 ptlrpc_deactivate_import(imp);
1137 IMPORT_SET_STATE(imp, LUSTRE_IMP_CLOSED);
1142 ptlrpc_maybe_ping_import_soon(imp);
1144 CDEBUG(D_HA, "recovery of %s on %s failed (%d)\n",
1145 obd2cli_tgt(imp->imp_obd),
1146 (char *)imp->imp_connection->c_remote_uuid.uuid, rc);
1149 spin_lock(&imp->imp_lock);
1150 imp->imp_last_recon = 0;
1151 spin_unlock(&imp->imp_lock);
1153 cfs_waitq_broadcast(&imp->imp_recovery_waitq);
1157 static int completed_replay_interpret(const struct lu_env *env,
1158 struct ptlrpc_request *req,
1159 void * data, int rc)
1162 atomic_dec(&req->rq_import->imp_replay_inflight);
1163 if (req->rq_status == 0 &&
1164 !req->rq_import->imp_vbr_failed) {
1165 ptlrpc_import_recovery_state_machine(req->rq_import);
1167 if (req->rq_import->imp_vbr_failed) {
1169 "%s: version recovery fails, reconnecting\n",
1170 req->rq_import->imp_obd->obd_name);
1171 spin_lock(&req->rq_import->imp_lock);
1172 req->rq_import->imp_vbr_failed = 0;
1173 spin_unlock(&req->rq_import->imp_lock);
1175 CDEBUG(D_HA, "%s: LAST_REPLAY message error: %d, "
1177 req->rq_import->imp_obd->obd_name,
1180 ptlrpc_connect_import(req->rq_import, NULL);
1186 static int signal_completed_replay(struct obd_import *imp)
1188 struct ptlrpc_request *req;
1191 LASSERT(atomic_read(&imp->imp_replay_inflight) == 0);
1192 atomic_inc(&imp->imp_replay_inflight);
1194 req = ptlrpc_request_alloc_pack(imp, &RQF_OBD_PING, LUSTRE_OBD_VERSION,
1197 atomic_dec(&imp->imp_replay_inflight);
1201 ptlrpc_request_set_replen(req);
1202 req->rq_send_state = LUSTRE_IMP_REPLAY_WAIT;
1203 lustre_msg_add_flags(req->rq_reqmsg,
1204 MSG_LOCK_REPLAY_DONE | MSG_REQ_REPLAY_DONE);
1205 req->rq_timeout *= 3;
1206 req->rq_interpret_reply = completed_replay_interpret;
1208 ptlrpcd_add_req(req, PSCOPE_OTHER);
1213 static int ptlrpc_invalidate_import_thread(void *data)
1215 struct obd_import *imp = data;
1219 ptlrpc_daemonize("ll_imp_inval");
1221 CDEBUG(D_HA, "thread invalidate import %s to %s@%s\n",
1222 imp->imp_obd->obd_name, obd2cli_tgt(imp->imp_obd),
1223 imp->imp_connection->c_remote_uuid.uuid);
1225 ptlrpc_invalidate_import(imp);
1227 if (obd_dump_on_eviction) {
1228 CERROR("dump the log upon eviction\n");
1229 libcfs_debug_dumplog();
1232 IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER);
1233 ptlrpc_import_recovery_state_machine(imp);
1235 class_import_put(imp);
1240 int ptlrpc_import_recovery_state_machine(struct obd_import *imp)
1248 if (imp->imp_state == LUSTRE_IMP_EVICTED) {
1249 deuuidify(obd2cli_tgt(imp->imp_obd), NULL,
1250 &target_start, &target_len);
1251 /* Don't care about MGC eviction */
1252 if (strcmp(imp->imp_obd->obd_type->typ_name,
1253 LUSTRE_MGC_NAME) != 0) {
1254 LCONSOLE_ERROR_MSG(0x167, "This client was evicted by "
1255 "%.*s; in progress operations using "
1256 "this service will fail.\n",
1257 target_len, target_start);
1259 CDEBUG(D_HA, "evicted from %s@%s; invalidating\n",
1260 obd2cli_tgt(imp->imp_obd),
1261 imp->imp_connection->c_remote_uuid.uuid);
1264 /* bug 17802: XXX client_disconnect_export vs connect request
1265 * race. if client will evicted at this time, we start
1266 * invalidate thread without referece to import and import can
1267 * be freed at same time. */
1268 class_import_get(imp);
1269 rc = cfs_kernel_thread(ptlrpc_invalidate_import_thread, imp,
1270 CLONE_VM | CLONE_FILES);
1272 class_import_put(imp);
1273 CERROR("error starting invalidate thread: %d\n", rc);
1279 ptlrpc_invalidate_import(imp);
1281 IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER);
1285 if (imp->imp_state == LUSTRE_IMP_REPLAY) {
1286 CDEBUG(D_HA, "replay requested by %s\n",
1287 obd2cli_tgt(imp->imp_obd));
1288 rc = ptlrpc_replay_next(imp, &inflight);
1289 if (inflight == 0 &&
1290 atomic_read(&imp->imp_replay_inflight) == 0) {
1291 IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY_LOCKS);
1292 rc = ldlm_replay_locks(imp);
1299 if (imp->imp_state == LUSTRE_IMP_REPLAY_LOCKS) {
1300 if (atomic_read(&imp->imp_replay_inflight) == 0) {
1301 IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY_WAIT);
1302 rc = signal_completed_replay(imp);
1309 if (imp->imp_state == LUSTRE_IMP_REPLAY_WAIT) {
1310 if (atomic_read(&imp->imp_replay_inflight) == 0) {
1311 IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER);
1315 if (imp->imp_state == LUSTRE_IMP_RECOVER) {
1316 CDEBUG(D_HA, "reconnected to %s@%s\n",
1317 obd2cli_tgt(imp->imp_obd),
1318 imp->imp_connection->c_remote_uuid.uuid);
1320 rc = ptlrpc_resend(imp);
1323 IMPORT_SET_STATE(imp, LUSTRE_IMP_FULL);
1324 ptlrpc_activate_import(imp);
1326 deuuidify(obd2cli_tgt(imp->imp_obd), NULL,
1327 &target_start, &target_len);
1328 LCONSOLE_INFO("%s: Connection restored to service %.*s "
1329 "using nid %s.\n", imp->imp_obd->obd_name,
1330 target_len, target_start,
1331 libcfs_nid2str(imp->imp_connection->c_peer.nid));
1334 if (imp->imp_state == LUSTRE_IMP_FULL) {
1335 cfs_waitq_broadcast(&imp->imp_recovery_waitq);
1336 ptlrpc_wake_delayed(imp);
1343 static int back_to_sleep(void *unused)
1348 int ptlrpc_disconnect_import(struct obd_import *imp, int noclose)
1350 struct ptlrpc_request *req;
1352 int nowait = imp->imp_obd->obd_force;
1356 GOTO(set_state, rc);
1358 switch (imp->imp_connect_op) {
1359 case OST_CONNECT: rq_opc = OST_DISCONNECT; break;
1360 case MDS_CONNECT: rq_opc = MDS_DISCONNECT; break;
1361 case MGS_CONNECT: rq_opc = MGS_DISCONNECT; break;
1363 CERROR("don't know how to disconnect from %s (connect_op %d)\n",
1364 obd2cli_tgt(imp->imp_obd), imp->imp_connect_op);
1368 if (ptlrpc_import_in_recovery(imp)) {
1369 struct l_wait_info lwi;
1370 cfs_duration_t timeout;
1374 if (imp->imp_server_timeout)
1375 timeout = cfs_time_seconds(obd_timeout / 2);
1377 timeout = cfs_time_seconds(obd_timeout);
1379 int idx = import_at_get_index(imp,
1380 imp->imp_client->cli_request_portal);
1381 timeout = cfs_time_seconds(
1382 at_get(&imp->imp_at.iat_service_estimate[idx]));
1385 lwi = LWI_TIMEOUT_INTR(cfs_timeout_cap(timeout),
1386 back_to_sleep, LWI_ON_SIGNAL_NOOP, NULL);
1387 rc = l_wait_event(imp->imp_recovery_waitq,
1388 !ptlrpc_import_in_recovery(imp), &lwi);
1392 spin_lock(&imp->imp_lock);
1393 if (imp->imp_state != LUSTRE_IMP_FULL)
1396 spin_unlock(&imp->imp_lock);
1398 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_DISCONNECT,
1399 LUSTRE_OBD_VERSION, rq_opc);
1401 /* We are disconnecting, do not retry a failed DISCONNECT rpc if
1402 * it fails. We can get through the above with a down server
1403 * if the client doesn't know the server is gone yet. */
1404 req->rq_no_resend = 1;
1407 /* We want client umounts to happen quickly, no matter the
1409 req->rq_timeout = min_t(int, req->rq_timeout,
1410 INITIAL_CONNECT_TIMEOUT);
1412 /* ... but we always want liblustre clients to nicely
1413 disconnect, so only use the adaptive value. */
1415 req->rq_timeout = obd_timeout / 3;
1418 IMPORT_SET_STATE(imp, LUSTRE_IMP_CONNECTING);
1419 req->rq_send_state = LUSTRE_IMP_CONNECTING;
1420 ptlrpc_request_set_replen(req);
1421 rc = ptlrpc_queue_wait(req);
1422 ptlrpc_req_finished(req);
1426 spin_lock(&imp->imp_lock);
1429 IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_DISCON);
1431 IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_CLOSED);
1432 memset(&imp->imp_remote_handle, 0, sizeof(imp->imp_remote_handle));
1433 /* Try all connections in the future - bz 12758 */
1434 imp->imp_last_recon = 0;
1435 spin_unlock(&imp->imp_lock);
1440 void ptlrpc_cleanup_imp(struct obd_import *imp)
1444 spin_lock(&imp->imp_lock);
1445 IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_CLOSED);
1446 imp->imp_generation++;
1447 spin_unlock(&imp->imp_lock);
1448 ptlrpc_abort_inflight(imp);
1453 /* Adaptive Timeout utils */
1454 extern unsigned int at_min, at_max, at_history;
1456 /* Bin into timeslices using AT_BINS bins.
1457 This gives us a max of the last binlimit*AT_BINS secs without the storage,
1458 but still smoothing out a return to normalcy from a slow response.
1459 (E.g. remember the maximum latency in each minute of the last 4 minutes.) */
1460 int at_add(struct adaptive_timeout *at, unsigned int val)
1462 unsigned int old = at->at_current;
1463 time_t now = cfs_time_current_sec();
1464 time_t binlimit = max_t(time_t, at_history / AT_BINS, 1);
1467 CDEBUG(D_OTHER, "add %u to %p time=%lu v=%u (%u %u %u %u)\n",
1468 val, at, now - at->at_binstart, at->at_current,
1469 at->at_hist[0], at->at_hist[1], at->at_hist[2], at->at_hist[3]);
1472 /* 0's don't count, because we never want our timeout to
1473 drop to 0, and because 0 could mean an error */
1476 spin_lock(&at->at_lock);
1478 if (unlikely(at->at_binstart == 0)) {
1479 /* Special case to remove default from history */
1480 at->at_current = val;
1481 at->at_worst_ever = val;
1482 at->at_worst_time = now;
1483 at->at_hist[0] = val;
1484 at->at_binstart = now;
1485 } else if (now - at->at_binstart < binlimit ) {
1487 at->at_hist[0] = max(val, at->at_hist[0]);
1488 at->at_current = max(val, at->at_current);
1491 unsigned int maxv = val;
1492 /* move bins over */
1493 shift = (now - at->at_binstart) / binlimit;
1495 for(i = AT_BINS - 1; i >= 0; i--) {
1497 at->at_hist[i] = at->at_hist[i - shift];
1498 maxv = max(maxv, at->at_hist[i]);
1503 at->at_hist[0] = val;
1504 at->at_current = maxv;
1505 at->at_binstart += shift * binlimit;
1508 if (at->at_current > at->at_worst_ever) {
1509 at->at_worst_ever = at->at_current;
1510 at->at_worst_time = now;
1513 if (at->at_flags & AT_FLG_NOHIST)
1514 /* Only keep last reported val; keeping the rest of the history
1516 at->at_current = val;
1519 at->at_current = min(at->at_current, at_max);
1520 at->at_current = max(at->at_current, at_min);
1522 if (at->at_current != old)
1523 CDEBUG(D_OTHER, "AT %p change: old=%u new=%u delta=%d "
1524 "(val=%u) hist %u %u %u %u\n", at,
1525 old, at->at_current, at->at_current - old, val,
1526 at->at_hist[0], at->at_hist[1], at->at_hist[2],
1529 /* if we changed, report the old value */
1530 old = (at->at_current != old) ? old : 0;
1532 spin_unlock(&at->at_lock);
1536 /* Find the imp_at index for a given portal; assign if space available */
1537 int import_at_get_index(struct obd_import *imp, int portal)
1539 struct imp_at *at = &imp->imp_at;
1542 for (i = 0; i < IMP_AT_MAX_PORTALS; i++) {
1543 if (at->iat_portal[i] == portal)
1545 if (at->iat_portal[i] == 0)
1550 /* Not found in list, add it under a lock */
1551 spin_lock(&imp->imp_lock);
1553 /* Check unused under lock */
1554 for (; i < IMP_AT_MAX_PORTALS; i++) {
1555 if (at->iat_portal[i] == portal)
1557 if (at->iat_portal[i] == 0)
1562 /* Not enough portals? */
1563 LASSERT(i < IMP_AT_MAX_PORTALS);
1565 at->iat_portal[i] = portal;
1567 spin_unlock(&imp->imp_lock);