From 6129f1bd555bbb96814c43b0c46344e6611391cb Mon Sep 17 00:00:00 2001
From: bobijam <bobijam>
Date: Thu, 6 Mar 2008 02:24:08 +0000
Subject: [PATCH] Branch b1_6 b=13715 i=johann i=nathan i=adilger

protect accessing imp->generation w/ imp_lock.
---
 lustre/ptlrpc/import.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/lustre/ptlrpc/import.c b/lustre/ptlrpc/import.c
index ca48d55db5..90da29b4aa 100644
--- a/lustre/ptlrpc/import.c
+++ b/lustre/ptlrpc/import.c
@@ -159,15 +159,12 @@ int ptlrpc_set_import_discon(struct obd_import *imp, __u32 conn_cnt)
         return rc;
 }
 
-/*
- * This acts as a barrier; all existing requests are rejected, and
- * no new requests will be accepted until the import is valid again.
- */
-void ptlrpc_deactivate_import(struct obd_import *imp)
+/* Must be called with imp_lock held! */
+static void ptlrpc_deactivate_and_unlock_import(struct obd_import *imp)
 {
         ENTRY;
+        LASSERT_SPIN_LOCKED(&imp->imp_lock);
 
-        spin_lock(&imp->imp_lock);
         CDEBUG(D_HA, "setting import %s INVALID\n", obd2cli_tgt(imp->imp_obd));
         imp->imp_invalid = 1;
         imp->imp_generation++;
@@ -177,6 +174,16 @@ void ptlrpc_deactivate_import(struct obd_import *imp)
         obd_import_event(imp->imp_obd, imp, IMP_EVENT_INACTIVE);
 }
 
+/*
+ * This acts as a barrier; all existing requests are rejected, and
+ * no new requests will be accepted until the import is valid again.
+ */
+void ptlrpc_deactivate_import(struct obd_import *imp)
+{
+        spin_lock(&imp->imp_lock);
+        ptlrpc_deactivate_and_unlock_import(imp);
+}
+
 /*
  * This function will invalidate the import, if necessary, then block
  * for all the RPC completions, and finally notify the obd to
@@ -880,9 +887,12 @@ finish:
  out:
         if (rc != 0) {
                 IMPORT_SET_STATE(imp, LUSTRE_IMP_DISCON);
+                spin_lock(&imp->imp_lock);
                 if (aa->pcaa_initial_connect && !imp->imp_initial_recov &&
                     (request->rq_import_generation == imp->imp_generation))
-                        ptlrpc_deactivate_import(imp);
+                        ptlrpc_deactivate_and_unlock_import(imp);
+                else
+                        spin_unlock(&imp->imp_lock);
 
                 if (imp->imp_recon_bk && imp->imp_last_recon) {
                         /* Give up trying to reconnect */
-- 
GitLab