Whamcloud - gitweb
b=15908
[fs/lustre-release.git] / lustre / ptlrpc / import.c
index 35f5c1f..2ea79c2 100644 (file)
@@ -34,6 +34,7 @@
 #include <lustre_import.h>
 #include <lustre_export.h>
 #include <obd.h>
+#include <obd_cksum.h>
 #include <obd_class.h>
 
 #include "ptlrpc_internal.h"
@@ -209,7 +210,15 @@ void ptlrpc_invalidate_import(struct obd_import *imp)
 
         atomic_inc(&imp->imp_inval_count);
 
-        ptlrpc_deactivate_import(imp);
+        /*
+         * If this is an invalid MGC connection, then don't bother
+         * waiting for imp_inflight to drop to 0.
+         */
+        if (imp->imp_invalid && imp->imp_recon_bk && !imp->imp_obd->obd_no_recov)
+                goto out;
+
+        if (!imp->imp_invalid || imp->imp_obd->obd_no_recov)
+                ptlrpc_deactivate_import(imp);
 
         LASSERT(imp->imp_invalid);
 
@@ -219,11 +228,26 @@ void ptlrpc_invalidate_import(struct obd_import *imp)
         rc = l_wait_event(imp->imp_recovery_waitq,
                           (atomic_read(&imp->imp_inflight) == 0), &lwi);
 
-        if (rc)
-                CDEBUG(D_HA, "%s: rc = %d waiting for callback (%d != 0)\n",
+        if (rc) {
+                struct list_head *tmp, *n;
+                struct ptlrpc_request *req;
+
+                CERROR("%s: rc = %d waiting for callback (%d != 0)\n",
                        obd2cli_tgt(imp->imp_obd), rc,
                        atomic_read(&imp->imp_inflight));
+                spin_lock(&imp->imp_lock);
+                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");
+                }
+                spin_unlock(&imp->imp_lock);
+        }
 
+out:
         obd_import_event(imp->imp_obd, imp, IMP_EVENT_INVALIDATE);
         sptlrpc_import_flush_all_ctx(imp);
 
@@ -271,6 +295,37 @@ void ptlrpc_fail_import(struct obd_import *imp, __u32 conn_cnt)
         EXIT;
 }
 
+int ptlrpc_reconnect_import(struct obd_import *imp)
+{
+        
+        ptlrpc_set_import_discon(imp, 0); 
+        /* Force a new connect attempt */
+        ptlrpc_invalidate_import(imp);
+        /* Do a fresh connect next time by zeroing the handle */
+        ptlrpc_disconnect_import(imp, 1);
+        /* Wait for all invalidate calls to finish */
+        if (atomic_read(&imp->imp_inval_count) > 0) {
+                int rc;
+                struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
+                rc = l_wait_event(imp->imp_recovery_waitq,
+                                  (atomic_read(&imp->imp_inval_count) == 0),
+                                  &lwi);
+                if (rc)
+                        CERROR("Interrupted, inval=%d\n", 
+                               atomic_read(&imp->imp_inval_count));
+        }
+
+        /* Allow reconnect attempts */
+        imp->imp_obd->obd_no_recov = 0;
+        /* Remove 'invalid' flag */
+        ptlrpc_activate_import(imp);
+        /* Attempt a new connect */
+        ptlrpc_recover_import(imp, NULL);
+        return 0;
+}
+
+EXPORT_SYMBOL(ptlrpc_reconnect_import);
+
 static int import_select_connection(struct obd_import *imp)
 {
         struct obd_import_conn *imp_conn = NULL, *conn;
@@ -605,20 +660,21 @@ static int ptlrpc_connect_interpret(struct ptlrpc_request *request,
                         spin_unlock(&imp->imp_lock);
                 }
 
-                if (msg_flags & MSG_CONNECT_NEXT_VER) {
-                        imp->imp_msg_magic = LUSTRE_MSG_MAGIC_V2;
-                        CDEBUG(D_RPCTRACE, "connect to %s with lustre_msg_v2\n",
-                               obd2cli_tgt(imp->imp_obd));
-                } else {
-                        CDEBUG(D_RPCTRACE, "connect to %s with lustre_msg_v1\n",
-                               obd2cli_tgt(imp->imp_obd));
-                }
+                /* if applies, adjust the imp->imp_msg_magic here
+                 * according to reply flags */
 
                 imp->imp_remote_handle =
                                 *lustre_msg_get_handle(request->rq_repmsg);
 
                 IMPORT_SET_STATE(imp, LUSTRE_IMP_FULL);
-                ptlrpc_activate_import(imp);
+                spin_lock(&imp->imp_lock);
+                if (imp->imp_invalid) {
+                        spin_unlock(&imp->imp_lock);
+                        ptlrpc_activate_import(imp);
+                } else {
+                        spin_unlock(&imp->imp_lock);
+                }
+
                 GOTO(finish, rc = 0);
         } else {
                 spin_unlock(&imp->imp_lock);
@@ -639,22 +695,19 @@ static int ptlrpc_connect_interpret(struct ptlrpc_request *request,
                 if (memcmp(&imp->imp_remote_handle,
                            lustre_msg_get_handle(request->rq_repmsg),
                            sizeof(imp->imp_remote_handle))) {
-                        int level = D_ERROR;
-                        /* Old MGC can reconnect to a restarted MGS */
-                        if (strcmp(imp->imp_obd->obd_type->typ_name,
-                                   LUSTRE_MGC_NAME) == 0) {
-                                level = D_CONFIG;
-                        }
-                        CDEBUG(level, 
-                               "%s@%s changed handle from "LPX64" to "LPX64
-                               "; copying, but this may foreshadow disaster\n",
+
+                        CWARN("%s@%s changed server handle from "
+                               LPX64" to "LPX64" - evicting.\n",
                                obd2cli_tgt(imp->imp_obd),
                                imp->imp_connection->c_remote_uuid.uuid,
                                imp->imp_remote_handle.cookie,
                                lustre_msg_get_handle(request->rq_repmsg)->
-                                        cookie);
+                                         cookie);
                         imp->imp_remote_handle =
                                      *lustre_msg_get_handle(request->rq_repmsg);
+
+                        IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED);
+                        GOTO(finish, rc = 0);
                 } else {
                         CDEBUG(D_HA, "reconnected to %s@%s after partition\n",
                                obd2cli_tgt(imp->imp_obd),
@@ -795,6 +848,38 @@ finish:
                                       newer : older, LUSTRE_VERSION_STRING);
                 }
 
+                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 & OBD_CKSUM_ALL) == 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,
+                                              OBD_CKSUM_ALL);
+                                cli->cl_checksum = 0;
+                                cli->cl_supp_cksum_types = OBD_CKSUM_CRC32;
+                                cli->cl_cksum_type = OBD_CKSUM_CRC32;
+                        } else {
+                                cli->cl_supp_cksum_types = ocd->ocd_cksum_types;
+
+                                if (ocd->ocd_cksum_types & OSC_DEFAULT_CKSUM)
+                                        cli->cl_cksum_type = OSC_DEFAULT_CKSUM;
+                                else if (ocd->ocd_cksum_types & OBD_CKSUM_ADLER)
+                                        cli->cl_cksum_type = OBD_CKSUM_ADLER;
+                                else
+                                        cli->cl_cksum_type = OBD_CKSUM_CRC32;
+                        }
+                } else {
+                        /* The server does not support OBD_CONNECT_CKSUM.
+                         * Enforce CRC32 for backward compatibility*/
+                        cli->cl_supp_cksum_types = OBD_CKSUM_CRC32;
+                        cli->cl_cksum_type = OBD_CKSUM_CRC32;
+                }
+
                 if (ocd->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
                         cli->cl_max_pages_per_rpc = 
                                 ocd->ocd_brw_size >> CFS_PAGE_SHIFT;