Whamcloud - gitweb
LU-395 Fix obd_zombie_barrier()
authorMikhail Pershin <tappro@whamcloud.com>
Mon, 6 Jun 2011 19:12:25 +0000 (23:12 +0400)
committerOleg Drokin <green@whamcloud.com>
Tue, 14 Jun 2011 00:05:50 +0000 (17:05 -0700)
The obd_zombie_barrier() is waiting for obd_zombie_export list is empty
and exit, but export may be not yet destroyed. This produces race between export
destroying and other cleanups like lut_fini()

The patch introduces zombies_in_destroy variable which is counter, and
obd_zombie_barrier is checking it.

Change-Id: I0fd4a1023efade1cb40d4c36e59169a25a525ed1
Signed-off-by: Mikhail Pershin <tappro@whamcloud.com>
Reviewed-on: http://review.whamcloud.com/899
Tested-by: Hudson
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/obdclass/genops.c

index 9a9adfa..e0a9416 100644 (file)
@@ -1464,6 +1464,9 @@ void obd_exports_barrier(struct obd_device *obd)
 }
 EXPORT_SYMBOL(obd_exports_barrier);
 
 }
 EXPORT_SYMBOL(obd_exports_barrier);
 
+/* Total amount of zombies to be destroyed */
+static int zombies_count = 0;
+
 /**
  * kill zombie imports and exports
  */
 /**
  * kill zombie imports and exports
  */
@@ -1494,11 +1497,19 @@ void obd_zombie_impexp_cull(void)
 
                 cfs_spin_unlock(&obd_zombie_impexp_lock);
 
 
                 cfs_spin_unlock(&obd_zombie_impexp_lock);
 
-                if (import != NULL)
+                if (import != NULL) {
                         class_import_destroy(import);
                         class_import_destroy(import);
+                        cfs_spin_lock(&obd_zombie_impexp_lock);
+                        zombies_count--;
+                        cfs_spin_unlock(&obd_zombie_impexp_lock);
+                }
 
 
-                if (export != NULL)
+                if (export != NULL) {
                         class_export_destroy(export);
                         class_export_destroy(export);
+                        cfs_spin_lock(&obd_zombie_impexp_lock);
+                        zombies_count--;
+                        cfs_spin_unlock(&obd_zombie_impexp_lock);
+                }
 
                 cfs_cond_resched();
         } while (import != NULL || export != NULL);
 
                 cfs_cond_resched();
         } while (import != NULL || export != NULL);
@@ -1523,10 +1534,8 @@ static int obd_zombie_impexp_check(void *arg)
         int rc;
 
         cfs_spin_lock(&obd_zombie_impexp_lock);
         int rc;
 
         cfs_spin_lock(&obd_zombie_impexp_lock);
-        rc = cfs_list_empty(&obd_zombie_imports) &&
-             cfs_list_empty(&obd_zombie_exports) &&
+        rc = (zombies_count == 0) &&
              !cfs_test_bit(OBD_ZOMBIE_STOP, &obd_zombie_flags);
              !cfs_test_bit(OBD_ZOMBIE_STOP, &obd_zombie_flags);
-
         cfs_spin_unlock(&obd_zombie_impexp_lock);
 
         RETURN(rc);
         cfs_spin_unlock(&obd_zombie_impexp_lock);
 
         RETURN(rc);
@@ -1541,6 +1550,7 @@ static void obd_zombie_export_add(struct obd_export *exp) {
         cfs_list_del_init(&exp->exp_obd_chain);
         cfs_spin_unlock(&exp->exp_obd->obd_dev_lock);
         cfs_spin_lock(&obd_zombie_impexp_lock);
         cfs_list_del_init(&exp->exp_obd_chain);
         cfs_spin_unlock(&exp->exp_obd->obd_dev_lock);
         cfs_spin_lock(&obd_zombie_impexp_lock);
+        zombies_count++;
         cfs_list_add(&exp->exp_obd_chain, &obd_zombie_exports);
         cfs_spin_unlock(&obd_zombie_impexp_lock);
 
         cfs_list_add(&exp->exp_obd_chain, &obd_zombie_exports);
         cfs_spin_unlock(&obd_zombie_impexp_lock);
 
@@ -1555,6 +1565,7 @@ static void obd_zombie_import_add(struct obd_import *imp) {
         LASSERT(imp->imp_sec == NULL);
         cfs_spin_lock(&obd_zombie_impexp_lock);
         LASSERT(cfs_list_empty(&imp->imp_zombie_chain));
         LASSERT(imp->imp_sec == NULL);
         cfs_spin_lock(&obd_zombie_impexp_lock);
         LASSERT(cfs_list_empty(&imp->imp_zombie_chain));
+        zombies_count++;
         cfs_list_add(&imp->imp_zombie_chain, &obd_zombie_imports);
         cfs_spin_unlock(&obd_zombie_impexp_lock);
 
         cfs_list_add(&imp->imp_zombie_chain, &obd_zombie_imports);
         cfs_spin_unlock(&obd_zombie_impexp_lock);
 
@@ -1579,8 +1590,7 @@ static int obd_zombie_is_idle(void)
 
         LASSERT(!cfs_test_bit(OBD_ZOMBIE_STOP, &obd_zombie_flags));
         cfs_spin_lock(&obd_zombie_impexp_lock);
 
         LASSERT(!cfs_test_bit(OBD_ZOMBIE_STOP, &obd_zombie_flags));
         cfs_spin_lock(&obd_zombie_impexp_lock);
-        rc = cfs_list_empty(&obd_zombie_imports) &&
-             cfs_list_empty(&obd_zombie_exports);
+        rc = (zombies_count == 0);
         cfs_spin_unlock(&obd_zombie_impexp_lock);
         return rc;
 }
         cfs_spin_unlock(&obd_zombie_impexp_lock);
         return rc;
 }