+struct ptlrpc_connect_async_args {
+ __u64 pcaa_peer_committed;
+ int pcaa_initial_connect;
+ int pcaa_was_invalid;
+};
+
+/* A CLOSED import should remain so. */
+#define IMPORT_SET_STATE_NOLOCK(imp, state) \
+do { \
+ if (imp->imp_state != LUSTRE_IMP_CLOSED) { \
+ CDEBUG(D_HA, "%p %s: changing import state from %s to %s\n", \
+ imp, imp->imp_target_uuid.uuid, \
+ ptlrpc_import_state_name(imp->imp_state), \
+ ptlrpc_import_state_name(state)); \
+ imp->imp_state = state; \
+ } \
+} while(0)
+
+#define IMPORT_SET_STATE(imp, state) \
+do { \
+ unsigned long flags; \
+ \
+ spin_lock_irqsave(&imp->imp_lock, flags); \
+ IMPORT_SET_STATE_NOLOCK(imp, state); \
+ spin_unlock_irqrestore(&imp->imp_lock, flags); \
+} while(0)
+
+
+static int ptlrpc_connect_interpret(struct ptlrpc_request *request,
+ void * data, int rc);
+int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
+
+/* Only this function is allowed to change the import state when it is
+ * CLOSED. I would rather refcount the import and free it after
+ * disconnection like we do with exports. To do that, the client_obd
+ * will need to save the peer info somewhere other than in the import,
+ * though. */
+int ptlrpc_init_import(struct obd_import *imp)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&imp->imp_lock, flags);
+
+ imp->imp_generation++;
+ imp->imp_state = LUSTRE_IMP_NEW;
+
+ spin_unlock_irqrestore(&imp->imp_lock, flags);
+
+ return 0;
+}
+
+/* Returns true if import was FULL, false if import was already not
+ * connected.
+ */
+int ptlrpc_set_import_discon(struct obd_import *imp)
+{
+ unsigned long flags;
+ int rc = 0;
+
+ spin_lock_irqsave(&imp->imp_lock, flags);
+
+ if (imp->imp_state == LUSTRE_IMP_FULL) {
+ IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_DISCON);
+ rc = 1;
+ } else {
+ CDEBUG(D_HA, "%p %s: import already not connected: %s\n",
+ imp,imp->imp_client->cli_name,
+ ptlrpc_import_state_name(imp->imp_state));
+ }
+ spin_unlock_irqrestore(&imp->imp_lock, flags);
+
+ return rc;
+}
+
+void ptlrpc_fail_import(struct obd_import *imp, int generation)
+{
+ ENTRY;
+
+ LASSERT (!imp->imp_dlm_fake);
+
+ if (ptlrpc_set_import_discon(imp))
+ ptlrpc_handle_failed_import(imp);
+
+ EXIT;
+}
+
+int ptlrpc_connect_import(struct obd_import *imp, char * new_uuid)