Whamcloud - gitweb
LU-6496 ptlrpc: Fix wrong code indentation in plain_authorize
[fs/lustre-release.git] / lustre / ptlrpc / import.c
index 19de797..e96396a 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2013, Intel Corporation.
+ * Copyright (c) 2011, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
  */
 
 #define DEBUG_SUBSYSTEM S_RPC
-#ifndef __KERNEL__
-# include <liblustre.h>
-#endif
 
+#include <linux/kthread.h>
 #include <obd_support.h>
 #include <lustre_ha.h>
 #include <lustre_net.h>
@@ -66,6 +64,18 @@ struct ptlrpc_connect_async_args {
 static void __import_set_state(struct obd_import *imp,
                                enum lustre_imp_state state)
 {
+       switch (state) {
+       case LUSTRE_IMP_CLOSED:
+       case LUSTRE_IMP_NEW:
+       case LUSTRE_IMP_DISCON:
+       case LUSTRE_IMP_CONNECTING:
+               break;
+       case LUSTRE_IMP_REPLAY_WAIT:
+               imp->imp_replay_state = LUSTRE_IMP_REPLAY_LOCKS;
+               break;
+       default:
+               imp->imp_replay_state = LUSTRE_IMP_REPLAY;
+       }
         imp->imp_state = state;
         imp->imp_state_hist[imp->imp_state_hist_idx].ish_state = state;
         imp->imp_state_hist[imp->imp_state_hist_idx].ish_time =
@@ -132,7 +142,6 @@ void deuuidify(char *uuid, const char *prefix, char **uuid_start, int *uuid_len)
                     UUID_STR, strlen(UUID_STR)))
                 *uuid_len -= strlen(UUID_STR);
 }
-EXPORT_SYMBOL(deuuidify);
 
 /**
  * Returns true if import was FULL, false if import was already not
@@ -249,13 +258,13 @@ ptlrpc_inflight_deadline(struct ptlrpc_request *req, time_t now)
 static unsigned int ptlrpc_inflight_timeout(struct obd_import *imp)
 {
        time_t now = cfs_time_current_sec();
-       cfs_list_t *tmp, *n;
+       struct list_head *tmp, *n;
        struct ptlrpc_request *req;
        unsigned int timeout = 0;
 
        spin_lock(&imp->imp_lock);
-       cfs_list_for_each_safe(tmp, n, &imp->imp_sending_list) {
-               req = cfs_list_entry(tmp, struct ptlrpc_request, rq_list);
+       list_for_each_safe(tmp, n, &imp->imp_sending_list) {
+               req = list_entry(tmp, struct ptlrpc_request, rq_list);
                timeout = max(ptlrpc_inflight_deadline(req, now), timeout);
        }
        spin_unlock(&imp->imp_lock);
@@ -270,7 +279,7 @@ static unsigned int ptlrpc_inflight_timeout(struct obd_import *imp)
  */
 void ptlrpc_invalidate_import(struct obd_import *imp)
 {
-       cfs_list_t *tmp, *n;
+       struct list_head *tmp, *n;
        struct ptlrpc_request *req;
        struct l_wait_info lwi;
        unsigned int timeout;
@@ -281,6 +290,7 @@ void ptlrpc_invalidate_import(struct obd_import *imp)
        if (!imp->imp_invalid || imp->imp_obd->obd_no_recov)
                ptlrpc_deactivate_import(imp);
 
+       CFS_FAIL_TIMEOUT(OBD_FAIL_MGS_CONNECT_NET, 3 * cfs_fail_val / 2);
        LASSERT(imp->imp_invalid);
 
         /* Wait forever until inflight == 0. We really can't do it another
@@ -338,23 +348,23 @@ void ptlrpc_invalidate_import(struct obd_import *imp)
                                 * dropped to zero. No new inflights possible at
                                 * this point. */
                                rc = 0;
-                        } else {
-                                cfs_list_for_each_safe(tmp, n,
-                                                       &imp->imp_sending_list) {
-                                        req = cfs_list_entry(tmp,
-                                                             struct ptlrpc_request,
-                                                             rq_list);
-                                        DEBUG_REQ(D_ERROR, req,
-                                                  "still on sending list");
-                                }
-                                cfs_list_for_each_safe(tmp, n,
-                                                       &imp->imp_delayed_list) {
-                                        req = cfs_list_entry(tmp,
-                                                             struct ptlrpc_request,
-                                                             rq_list);
-                                        DEBUG_REQ(D_ERROR, req,
-                                                  "still on delayed list");
-                                }
+                       } else {
+                               list_for_each_safe(tmp, n,
+                                                  &imp->imp_sending_list) {
+                                       req = list_entry(tmp,
+                                                        struct ptlrpc_request,
+                                                        rq_list);
+                                       DEBUG_REQ(D_ERROR, req,
+                                                 "still on sending list");
+                               }
+                               list_for_each_safe(tmp, n,
+                                                  &imp->imp_delayed_list) {
+                                       req = list_entry(tmp,
+                                                        struct ptlrpc_request,
+                                                        rq_list);
+                                       DEBUG_REQ(D_ERROR, req,
+                                                 "still on delayed list");
+                               }
 
                                CERROR("%s: RPCs in \"%s\" phase found (%d). "
                                       "Network is sluggish? Waiting them "
@@ -396,6 +406,19 @@ void ptlrpc_activate_import(struct obd_import *imp)
 }
 EXPORT_SYMBOL(ptlrpc_activate_import);
 
+static void ptlrpc_pinger_force(struct obd_import *imp)
+{
+       CDEBUG(D_HA, "%s: waking up pinger s:%s\n", obd2cli_tgt(imp->imp_obd),
+              ptlrpc_import_state_name(imp->imp_state));
+
+       spin_lock(&imp->imp_lock);
+       imp->imp_force_verify = 1;
+       spin_unlock(&imp->imp_lock);
+
+       if (imp->imp_state != LUSTRE_IMP_CONNECTING)
+               ptlrpc_pinger_wake_up();
+}
+
 void ptlrpc_fail_import(struct obd_import *imp, __u32 conn_cnt)
 {
         ENTRY;
@@ -412,21 +435,30 @@ void ptlrpc_fail_import(struct obd_import *imp, __u32 conn_cnt)
                         ptlrpc_deactivate_import(imp);
                 }
 
-                CDEBUG(D_HA, "%s: waking up pinger\n",
-                       obd2cli_tgt(imp->imp_obd));
-
-               spin_lock(&imp->imp_lock);
-               imp->imp_force_verify = 1;
-               spin_unlock(&imp->imp_lock);
-
-               ptlrpc_pinger_wake_up();
+               ptlrpc_pinger_force(imp);
        }
        EXIT;
 }
-EXPORT_SYMBOL(ptlrpc_fail_import);
 
 int ptlrpc_reconnect_import(struct obd_import *imp)
 {
+#ifdef ENABLE_PINGER
+       struct l_wait_info lwi;
+       int secs = cfs_time_seconds(obd_timeout);
+       int rc;
+
+       ptlrpc_pinger_force(imp);
+
+       CDEBUG(D_HA, "%s: recovery started, waiting %u seconds\n",
+              obd2cli_tgt(imp->imp_obd), secs);
+
+       lwi = LWI_TIMEOUT(secs, NULL, NULL);
+       rc = l_wait_event(imp->imp_recovery_waitq,
+                         !ptlrpc_import_in_recovery(imp), &lwi);
+       CDEBUG(D_HA, "%s: recovery finished s:%s\n", obd2cli_tgt(imp->imp_obd),
+              ptlrpc_import_state_name(imp->imp_state));
+       return rc;
+#else
        ptlrpc_set_import_discon(imp, 0);
        /* Force a new connect attempt */
        ptlrpc_invalidate_import(imp);
@@ -452,6 +484,7 @@ int ptlrpc_reconnect_import(struct obd_import *imp)
        /* Attempt a new connect */
        ptlrpc_recover_import(imp, NULL, 0);
        return 0;
+#endif
 }
 EXPORT_SYMBOL(ptlrpc_reconnect_import);
 
@@ -470,14 +503,14 @@ static int import_select_connection(struct obd_import *imp)
 
        spin_lock(&imp->imp_lock);
 
-       if (cfs_list_empty(&imp->imp_conn_list)) {
+       if (list_empty(&imp->imp_conn_list)) {
                CERROR("%s: no connections available\n",
                       imp->imp_obd->obd_name);
                spin_unlock(&imp->imp_lock);
                RETURN(-EINVAL);
        }
 
-        cfs_list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
+       list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
                 CDEBUG(D_HA, "%s: connect to NID %s last attempt "LPU64"\n",
                        imp->imp_obd->obd_name,
                        libcfs_nid2str(conn->oic_conn->c_peer.nid),
@@ -572,13 +605,13 @@ static int import_select_connection(struct obd_import *imp)
 static int ptlrpc_first_transno(struct obd_import *imp, __u64 *transno)
 {
        struct ptlrpc_request   *req;
-       cfs_list_t              *tmp;
+       struct list_head        *tmp;
 
        /* The requests in committed_list always have smaller transnos than
         * the requests in replay_list */
-       if (!cfs_list_empty(&imp->imp_committed_list)) {
+       if (!list_empty(&imp->imp_committed_list)) {
                tmp = imp->imp_committed_list.next;
-               req = cfs_list_entry(tmp, struct ptlrpc_request, rq_replay_list);
+               req = list_entry(tmp, struct ptlrpc_request, rq_replay_list);
                *transno = req->rq_transno;
                if (req->rq_transno == 0) {
                        DEBUG_REQ(D_ERROR, req, "zero transno in committed_list");
@@ -586,9 +619,9 @@ static int ptlrpc_first_transno(struct obd_import *imp, __u64 *transno)
                }
                return 1;
        }
-       if (!cfs_list_empty(&imp->imp_replay_list)) {
+       if (!list_empty(&imp->imp_replay_list)) {
                tmp = imp->imp_replay_list.next;
-               req = cfs_list_entry(tmp, struct ptlrpc_request, rq_replay_list);
+               req = list_entry(tmp, struct ptlrpc_request, rq_replay_list);
                *transno = req->rq_transno;
                if (req->rq_transno == 0) {
                        DEBUG_REQ(D_ERROR, req, "zero transno in replay_list");
@@ -654,7 +687,7 @@ int ptlrpc_connect_import(struct obd_import *imp)
         if (rc)
                 GOTO(out, rc);
 
-        rc = sptlrpc_import_sec_adapt(imp, NULL, 0);
+       rc = sptlrpc_import_sec_adapt(imp, NULL, NULL);
         if (rc)
                 GOTO(out, rc);
 
@@ -695,11 +728,6 @@ int ptlrpc_connect_import(struct obd_import *imp)
         request->rq_timeout = INITIAL_CONNECT_TIMEOUT;
         lustre_msg_set_timeout(request->rq_reqmsg, request->rq_timeout);
 
-#ifndef __KERNEL__
-        lustre_msg_add_op_flags(request->rq_reqmsg, MSG_CONNECT_LIBCLIENT);
-#endif
-        lustre_msg_add_op_flags(request->rq_reqmsg, MSG_CONNECT_NEXT_VER);
-
         request->rq_no_resend = request->rq_no_delay = 1;
         request->rq_send_state = LUSTRE_IMP_CONNECTING;
         /* Allow a slightly larger reply for future growth compatibility */
@@ -742,7 +770,6 @@ EXPORT_SYMBOL(ptlrpc_connect_import);
 
 static void ptlrpc_maybe_ping_import_soon(struct obd_import *imp)
 {
-#ifdef __KERNEL__
        int force_verify;
 
        spin_lock(&imp->imp_lock);
@@ -751,10 +778,6 @@ static void ptlrpc_maybe_ping_import_soon(struct obd_import *imp)
 
        if (force_verify)
                ptlrpc_pinger_wake_up();
-#else
-        /* liblustre has no pinger thread, so we wakeup pinger anyway */
-       ptlrpc_pinger_wake_up();
-#endif
 }
 
 static int ptlrpc_busy_reconnect(int rc)
@@ -762,6 +785,150 @@ static int ptlrpc_busy_reconnect(int rc)
         return (rc == -EBUSY) || (rc == -EAGAIN);
 }
 
+static int ptlrpc_connect_set_flags(struct obd_import *imp,
+                                    struct obd_connect_data *ocd,
+                                    __u64 old_connect_flags,
+                                    struct obd_export *exp, int init_connect)
+{
+       static bool warned;
+       struct client_obd *cli = &imp->imp_obd->u.cli;
+
+       if ((imp->imp_connect_flags_orig & OBD_CONNECT_IBITS) &&
+           !(ocd->ocd_connect_flags & OBD_CONNECT_IBITS)) {
+               LCONSOLE_WARN("%s: MDS %s does not support ibits "
+                             "lock, either very old or invalid: "
+                             "requested "LPX64", replied "LPX64"\n",
+                             imp->imp_obd->obd_name,
+                             imp->imp_connection->c_remote_uuid.uuid,
+                             imp->imp_connect_flags_orig,
+                             ocd->ocd_connect_flags);
+               return -EPROTO;
+       }
+
+       spin_lock(&imp->imp_lock);
+       list_del(&imp->imp_conn_current->oic_item);
+       list_add(&imp->imp_conn_current->oic_item,
+                &imp->imp_conn_list);
+       imp->imp_last_success_conn =
+               imp->imp_conn_current->oic_last_attempt;
+
+       spin_unlock(&imp->imp_lock);
+
+
+       if (!warned && (ocd->ocd_connect_flags & OBD_CONNECT_VERSION) &&
+           (ocd->ocd_version > LUSTRE_VERSION_CODE +
+                               LUSTRE_VERSION_OFFSET_WARN ||
+            ocd->ocd_version < LUSTRE_VERSION_CODE -
+                               LUSTRE_VERSION_OFFSET_WARN)) {
+               /* Sigh, some compilers do not like #ifdef in the middle
+                  of macro arguments */
+               const char *older = "older than client. "
+                                   "Consider upgrading server";
+               const char *newer = "newer than client. "
+                                   "Consider recompiling application";
+
+               LCONSOLE_WARN("Server %s version (%d.%d.%d.%d) "
+                             "is much %s (%s)\n",
+                             obd2cli_tgt(imp->imp_obd),
+                             OBD_OCD_VERSION_MAJOR(ocd->ocd_version),
+                             OBD_OCD_VERSION_MINOR(ocd->ocd_version),
+                             OBD_OCD_VERSION_PATCH(ocd->ocd_version),
+                             OBD_OCD_VERSION_FIX(ocd->ocd_version),
+                             ocd->ocd_version > LUSTRE_VERSION_CODE ?
+                             newer : older, LUSTRE_VERSION_STRING);
+               warned = true;
+       }
+
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
+       /* Check if server has LU-1252 fix applied to not always swab
+        * the IR MNE entries. Do this only once per connection.  This
+        * fixup is version-limited, because we don't want to carry the
+        * OBD_CONNECT_MNE_SWAB flag around forever, just so long as we
+        * need interop with unpatched 2.2 servers.  For newer servers,
+        * the client will do MNE swabbing only as needed.  LU-1644 */
+       if (unlikely((ocd->ocd_connect_flags & OBD_CONNECT_VERSION) &&
+                    !(ocd->ocd_connect_flags & OBD_CONNECT_MNE_SWAB) &&
+                    OBD_OCD_VERSION_MAJOR(ocd->ocd_version) == 2 &&
+                    OBD_OCD_VERSION_MINOR(ocd->ocd_version) == 2 &&
+                    OBD_OCD_VERSION_PATCH(ocd->ocd_version) < 55 &&
+                    strcmp(imp->imp_obd->obd_type->typ_name,
+                           LUSTRE_MGC_NAME) == 0))
+               imp->imp_need_mne_swab = 1;
+       else /* clear if server was upgraded since last connect */
+               imp->imp_need_mne_swab = 0;
+#endif
+
+       if (ocd->ocd_connect_flags & OBD_CONNECT_CKSUM) {
+               /* We sent to the server ocd_cksum_types with bits set
+                * for algorithms we understand. The server masked off
+                * the checksum types it doesn't support */
+               if ((ocd->ocd_cksum_types &
+                    cksum_types_supported_client()) == 0) {
+                       LCONSOLE_WARN("The negotiation of the checksum "
+                                     "alogrithm to use with server %s "
+                                     "failed (%x/%x), disabling "
+                                     "checksums\n",
+                                     obd2cli_tgt(imp->imp_obd),
+                                     ocd->ocd_cksum_types,
+                                     cksum_types_supported_client());
+                       cli->cl_checksum = 0;
+                       cli->cl_supp_cksum_types = OBD_CKSUM_ADLER;
+               } else {
+                       cli->cl_supp_cksum_types = ocd->ocd_cksum_types;
+               }
+       } else {
+               /* The server does not support OBD_CONNECT_CKSUM.
+                * Enforce ADLER for backward compatibility*/
+               cli->cl_supp_cksum_types = OBD_CKSUM_ADLER;
+       }
+       cli->cl_cksum_type = cksum_type_select(cli->cl_supp_cksum_types);
+
+       if (ocd->ocd_connect_flags & OBD_CONNECT_BRW_SIZE)
+               cli->cl_max_pages_per_rpc =
+                       min(ocd->ocd_brw_size >> PAGE_CACHE_SHIFT,
+                           cli->cl_max_pages_per_rpc);
+       else if (imp->imp_connect_op == MDS_CONNECT ||
+                imp->imp_connect_op == MGS_CONNECT)
+               cli->cl_max_pages_per_rpc = 1;
+
+       LASSERT((cli->cl_max_pages_per_rpc <= PTLRPC_MAX_BRW_PAGES) &&
+               (cli->cl_max_pages_per_rpc > 0));
+
+       client_adjust_max_dirty(cli);
+
+
+       /* Reset ns_connect_flags only for initial connect. It might be
+        * changed in while using FS and if we reset it in reconnect
+        * this leads to losing user settings done before such as
+        * disable lru_resize, etc. */
+       if (old_connect_flags != exp_connect_flags(exp) || init_connect) {
+               CDEBUG(D_HA, "%s: Resetting ns_connect_flags to server "
+                            "flags: "LPX64"\n", imp->imp_obd->obd_name,
+                            ocd->ocd_connect_flags);
+               imp->imp_obd->obd_namespace->ns_connect_flags =
+                       ocd->ocd_connect_flags;
+               imp->imp_obd->obd_namespace->ns_orig_connect_flags =
+                       ocd->ocd_connect_flags;
+       }
+
+       if (ocd->ocd_connect_flags & OBD_CONNECT_AT)
+               /* We need a per-message support flag, because
+                * a. we don't know if the incoming connect reply
+                *    supports AT or not (in reply_in_callback)
+                *    until we unpack it.
+                * b. failovered server means export and flags are gone
+                *    (in ptlrpc_send_reply).
+                *    Can only be set when we know AT is supported at
+                *    both ends */
+               imp->imp_msghdr_flags |= MSGHDR_AT_SUPPORT;
+       else
+               imp->imp_msghdr_flags &= ~MSGHDR_AT_SUPPORT;
+
+       imp->imp_msghdr_flags |= MSGHDR_CKSUM_INCOMPAT18;
+
+       return 0;
+}
+
 /**
  * interpret_reply callback for connect RPCs.
  * Looks into returned status of connect operation and decides
@@ -774,7 +941,6 @@ static int ptlrpc_connect_interpret(const struct lu_env *env,
 {
         struct ptlrpc_connect_async_args *aa = data;
         struct obd_import *imp = request->rq_import;
-        struct client_obd *cli = &imp->imp_obd->u.cli;
         struct lustre_handle old_hdl;
         __u64 old_connect_flags;
         int msg_flags;
@@ -842,6 +1008,32 @@ static int ptlrpc_connect_interpret(const struct lu_env *env,
                GOTO(out, rc = -EPROTO);
        }
 
+       if (!(imp->imp_connect_flags_orig & OBD_CONNECT_LIGHTWEIGHT) &&
+           (imp->imp_connect_flags_orig & OBD_CONNECT_MDS_MDS) &&
+           (imp->imp_connect_flags_orig & OBD_CONNECT_FID) &&
+           (ocd->ocd_connect_flags & OBD_CONNECT_VERSION)) {
+               __u32 major = OBD_OCD_VERSION_MAJOR(ocd->ocd_version);
+               __u32 minor = OBD_OCD_VERSION_MINOR(ocd->ocd_version);
+               __u32 patch = OBD_OCD_VERSION_PATCH(ocd->ocd_version);
+
+               /* We do not support the MDT-MDT interoperations with
+                * different version MDT because of protocol changes. */
+               if (unlikely(major != LUSTRE_MAJOR ||
+                            minor != LUSTRE_MINOR ||
+                            abs(patch - LUSTRE_PATCH) > 3)) {
+                       LCONSOLE_WARN("%s: import %p (%u.%u.%u.%u) tried the "
+                                     "connection to different version MDT "
+                                     "(%d.%d.%d.%d) %s\n",
+                                     imp->imp_obd->obd_name, imp, LUSTRE_MAJOR,
+                                     LUSTRE_MINOR, LUSTRE_PATCH, LUSTRE_FIX,
+                                     major, minor, patch,
+                                     OBD_OCD_VERSION_FIX(ocd->ocd_version),
+                                     imp->imp_connection->c_remote_uuid.uuid);
+
+                       GOTO(out, rc = -EPROTO);
+               }
+       }
+
        if (!exp) {
                /* This could happen if export is cleaned during the
                   connect attempt */
@@ -852,7 +1044,19 @@ static int ptlrpc_connect_interpret(const struct lu_env *env,
        old_connect_flags = exp_connect_flags(exp);
        exp->exp_connect_data = *ocd;
        imp->imp_obd->obd_self_export->exp_connect_data = *ocd;
+
+       /* The net statistics after (re-)connect is not valid anymore,
+        * because may reflect other routing, etc. */
+       at_init(&imp->imp_at.iat_net_latency, 0, 0);
+       ptlrpc_at_adj_net_latency(request,
+                       lustre_msg_get_service_time(request->rq_repmsg));
+
+       /* Import flags should be updated before waking import at FULL state */
+       rc = ptlrpc_connect_set_flags(imp, ocd, old_connect_flags, exp,
+                                aa->pcaa_initial_connect);
        class_export_put(exp);
+       if (rc != 0)
+               GOTO(out, rc);
 
        obd_import_event(imp->imp_obd, imp, IMP_EVENT_OCD);
 
@@ -882,8 +1086,8 @@ static int ptlrpc_connect_interpret(const struct lu_env *env,
                                obd2cli_tgt(imp->imp_obd));
                         IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY_LOCKS);
                 } else {
-                        IMPORT_SET_STATE(imp, LUSTRE_IMP_FULL);
-                        ptlrpc_activate_import(imp);
+                       IMPORT_SET_STATE(imp, LUSTRE_IMP_FULL);
+                       ptlrpc_activate_import(imp);
                 }
 
                 GOTO(finish, rc = 0);
@@ -964,7 +1168,7 @@ static int ptlrpc_connect_interpret(const struct lu_env *env,
                        imp->imp_resend_replay = 1;
                        spin_unlock(&imp->imp_lock);
 
-                        IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY);
+                       IMPORT_SET_STATE(imp, imp->imp_replay_state);
                 } else {
                         IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER);
                 }
@@ -1001,155 +1205,15 @@ static int ptlrpc_connect_interpret(const struct lu_env *env,
 
 finish:
        rc = ptlrpc_import_recovery_state_machine(imp);
-       if (rc != 0) {
-               if (rc == -ENOTCONN) {
-                       CDEBUG(D_HA, "evicted/aborted by %s@%s during recovery;"
-                              "invalidating and reconnecting\n",
-                              obd2cli_tgt(imp->imp_obd),
-                              imp->imp_connection->c_remote_uuid.uuid);
-                       ptlrpc_connect_import(imp);
-                       imp->imp_connect_tried = 1;
-                       RETURN(0);
-               }
-       } else {
-               static bool warned;
-
-               spin_lock(&imp->imp_lock);
-               cfs_list_del(&imp->imp_conn_current->oic_item);
-               cfs_list_add(&imp->imp_conn_current->oic_item,
-                            &imp->imp_conn_list);
-               imp->imp_last_success_conn =
-                       imp->imp_conn_current->oic_last_attempt;
-
-               spin_unlock(&imp->imp_lock);
-
-               if (!ocd->ocd_ibits_known &&
-                   ocd->ocd_connect_flags & OBD_CONNECT_IBITS)
-                       CERROR("Inodebits aware server returned zero compatible"
-                              " bits?\n");
-
-               if (!warned && (ocd->ocd_connect_flags & OBD_CONNECT_VERSION) &&
-                   (ocd->ocd_version > LUSTRE_VERSION_CODE +
-                                       LUSTRE_VERSION_OFFSET_WARN ||
-                    ocd->ocd_version < LUSTRE_VERSION_CODE -
-                                       LUSTRE_VERSION_OFFSET_WARN)) {
-                       /* Sigh, some compilers do not like #ifdef in the middle
-                          of macro arguments */
-                       const char *older = "older than client. "
-                                           "Consider upgrading server";
-#ifdef __KERNEL__
-                       const char *newer = "newer than client. "
-                                           "Consider recompiling application";
-#else
-                       const char *newer = "newer than client. "
-                                           "Consider upgrading client";
-#endif
-
-                       LCONSOLE_WARN("Server %s version (%d.%d.%d.%d) "
-                                     "is much %s (%s)\n",
-                                     obd2cli_tgt(imp->imp_obd),
-                                     OBD_OCD_VERSION_MAJOR(ocd->ocd_version),
-                                     OBD_OCD_VERSION_MINOR(ocd->ocd_version),
-                                     OBD_OCD_VERSION_PATCH(ocd->ocd_version),
-                                     OBD_OCD_VERSION_FIX(ocd->ocd_version),
-                                     ocd->ocd_version > LUSTRE_VERSION_CODE ?
-                                     newer : older, LUSTRE_VERSION_STRING);
-                       warned = true;
-               }
-
-#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 2, 50, 0)
-               /* Check if server has LU-1252 fix applied to not always swab
-                * the IR MNE entries. Do this only once per connection.  This
-                * fixup is version-limited, because we don't want to carry the
-                * OBD_CONNECT_MNE_SWAB flag around forever, just so long as we
-                * need interop with unpatched 2.2 servers.  For newer servers,
-                * the client will do MNE swabbing only as needed.  LU-1644 */
-               if (unlikely((ocd->ocd_connect_flags & OBD_CONNECT_VERSION) &&
-                            !(ocd->ocd_connect_flags & OBD_CONNECT_MNE_SWAB) &&
-                            OBD_OCD_VERSION_MAJOR(ocd->ocd_version) == 2 &&
-                            OBD_OCD_VERSION_MINOR(ocd->ocd_version) == 2 &&
-                            OBD_OCD_VERSION_PATCH(ocd->ocd_version) < 55 &&
-                            strcmp(imp->imp_obd->obd_type->typ_name,
-                                   LUSTRE_MGC_NAME) == 0))
-                       imp->imp_need_mne_swab = 1;
-               else /* clear if server was upgraded since last connect */
-                       imp->imp_need_mne_swab = 0;
-#else
-#warning "LU-1644: Remove old OBD_CONNECT_MNE_SWAB fixup and imp_need_mne_swab"
-#endif
-
-               if (ocd->ocd_connect_flags & OBD_CONNECT_CKSUM) {
-                       /* We sent to the server ocd_cksum_types with bits set
-                        * for algorithms we understand. The server masked off
-                        * the checksum types it doesn't support */
-                       if ((ocd->ocd_cksum_types &
-                            cksum_types_supported_client()) == 0) {
-                               LCONSOLE_WARN("The negotiation of the checksum "
-                                             "alogrithm to use with server %s "
-                                             "failed (%x/%x), disabling "
-                                             "checksums\n",
-                                             obd2cli_tgt(imp->imp_obd),
-                                             ocd->ocd_cksum_types,
-                                             cksum_types_supported_client());
-                               cli->cl_checksum = 0;
-                               cli->cl_supp_cksum_types = OBD_CKSUM_ADLER;
-                       } else {
-                               cli->cl_supp_cksum_types = ocd->ocd_cksum_types;
-                       }
-               } else {
-                       /* The server does not support OBD_CONNECT_CKSUM.
-                        * Enforce ADLER for backward compatibility*/
-                       cli->cl_supp_cksum_types = OBD_CKSUM_ADLER;
-               }
-               cli->cl_cksum_type =cksum_type_select(cli->cl_supp_cksum_types);
-
-               if (ocd->ocd_connect_flags & OBD_CONNECT_BRW_SIZE)
-                       cli->cl_max_pages_per_rpc =
-                               min(ocd->ocd_brw_size >> PAGE_CACHE_SHIFT,
-                                   cli->cl_max_pages_per_rpc);
-               else if (imp->imp_connect_op == MDS_CONNECT ||
-                        imp->imp_connect_op == MGS_CONNECT)
-                       cli->cl_max_pages_per_rpc = 1;
-
-               /* Reset ns_connect_flags only for initial connect. It might be
-                * changed in while using FS and if we reset it in reconnect
-                * this leads to losing user settings done before such as
-                * disable lru_resize, etc. */
-               if (old_connect_flags != exp_connect_flags(exp) ||
-                   aa->pcaa_initial_connect) {
-                        CDEBUG(D_HA, "%s: Resetting ns_connect_flags to server "
-                               "flags: "LPX64"\n", imp->imp_obd->obd_name,
-                              ocd->ocd_connect_flags);
-                        imp->imp_obd->obd_namespace->ns_connect_flags =
-                                ocd->ocd_connect_flags;
-                        imp->imp_obd->obd_namespace->ns_orig_connect_flags =
-                                ocd->ocd_connect_flags;
-                }
-
-                if ((ocd->ocd_connect_flags & OBD_CONNECT_AT) &&
-                    (imp->imp_msg_magic == LUSTRE_MSG_MAGIC_V2))
-                        /* We need a per-message support flag, because
-                           a. we don't know if the incoming connect reply
-                              supports AT or not (in reply_in_callback)
-                              until we unpack it.
-                           b. failovered server means export and flags are gone
-                              (in ptlrpc_send_reply).
-                           Can only be set when we know AT is supported at
-                           both ends */
-                        imp->imp_msghdr_flags |= MSGHDR_AT_SUPPORT;
-                else
-                        imp->imp_msghdr_flags &= ~MSGHDR_AT_SUPPORT;
-
-                if ((ocd->ocd_connect_flags & OBD_CONNECT_FULL20) &&
-                    (imp->imp_msg_magic == LUSTRE_MSG_MAGIC_V2))
-                        imp->imp_msghdr_flags |= MSGHDR_CKSUM_INCOMPAT18;
-                else
-                        imp->imp_msghdr_flags &= ~MSGHDR_CKSUM_INCOMPAT18;
-
-                LASSERT((cli->cl_max_pages_per_rpc <= PTLRPC_MAX_BRW_PAGES) &&
-                        (cli->cl_max_pages_per_rpc > 0));
-               client_adjust_max_dirty(cli);
-        }
+       if (rc == -ENOTCONN) {
+               CDEBUG(D_HA, "evicted/aborted by %s@%s during recovery;"
+                      "invalidating and reconnecting\n",
+                      obd2cli_tgt(imp->imp_obd),
+                      imp->imp_connection->c_remote_uuid.uuid);
+               ptlrpc_connect_import(imp);
+               imp->imp_connect_tried = 1;
+               RETURN(0);
+       }
 
 out:
        imp->imp_connect_tried = 1;
@@ -1272,7 +1336,6 @@ static int signal_completed_replay(struct obd_import *imp)
        RETURN(0);
 }
 
-#ifdef __KERNEL__
 /**
  * In kernel code all import invalidation happens in its own
  * separate thread, so that whatever application happened to encounter
@@ -1303,7 +1366,6 @@ static int ptlrpc_invalidate_import_thread(void *data)
         class_import_put(imp);
         RETURN(0);
 }
-#endif
 
 /**
  * This is the state machine for client-side recovery on import.
@@ -1353,11 +1415,10 @@ int ptlrpc_import_recovery_state_machine(struct obd_import *imp)
                imp->imp_vbr_failed = 0;
                spin_unlock(&imp->imp_lock);
 
-#ifdef __KERNEL__
                {
                struct task_struct *task;
                /* bug 17802:  XXX client_disconnect_export vs connect request
-                * race. if client will evicted at this time, we start
+                * race. if client is evicted at this time then we start
                 * invalidate thread without reference to import and import can
                 * be freed at same time. */
                class_import_get(imp);
@@ -1372,11 +1433,6 @@ int ptlrpc_import_recovery_state_machine(struct obd_import *imp)
                }
                RETURN(rc);
                }
-#else
-                ptlrpc_invalidate_import(imp);
-
-                IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER);
-#endif
         }
 
        if (imp->imp_state == LUSTRE_IMP_REPLAY) {
@@ -1540,7 +1596,6 @@ void ptlrpc_cleanup_imp(struct obd_import *imp)
 
        EXIT;
 }
-EXPORT_SYMBOL(ptlrpc_cleanup_imp);
 
 /* Adaptive Timeout utils */
 extern unsigned int at_min, at_max, at_history;