Whamcloud - gitweb
b=22683 fix unbalanced cl_env hash.
[fs/lustre-release.git] / lustre / obdclass / cl_object.c
index f8ef9f7..1d6572d 100644 (file)
@@ -26,7 +26,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  */
 /*
@@ -536,7 +536,10 @@ struct cl_env {
         cfs_hlist_node_t  ce_node;
         /**
          * Owner for the current cl_env, the key for cfs_hash.
-         * Now current thread pointer is stored.
+         * Now current thread pid is stored. Note using thread pointer would
+         * lead to unbalanced hash because of its specific allocation locality
+         * and could be varied for different platforms and OSes, even different
+         * OS versions.
          */
         void             *ce_owner;
         /*
@@ -607,7 +610,7 @@ static cfs_hash_ops_t cl_env_hops = {
 static inline struct cl_env *cl_env_fetch(void)
 {
         struct cl_env *cle;
-        cle = cfs_hash_lookup(cl_env_hash, cfs_current());
+        cle = cfs_hash_lookup(cl_env_hash, (void *) (long) cfs_current()->pid);
         LASSERT(ergo(cle, cle->ce_magic == &cl_env_init0));
         return cle;
 }
@@ -617,9 +620,9 @@ static inline void cl_env_attach(struct cl_env *cle)
         if (cle) {
                 int rc;
                 LASSERT(cle->ce_owner == NULL);
-                cle->ce_owner = cfs_current();
+                cle->ce_owner = (void *) (long) cfs_current()->pid;
                 rc = cfs_hash_add_unique(cl_env_hash, cle->ce_owner,
-                                            &cle->ce_node);
+                                         &cle->ce_node);
                 LASSERT(rc == 0);
         }
 }
@@ -630,9 +633,9 @@ static inline struct cl_env *cl_env_detach(struct cl_env *cle)
                 cle = cl_env_fetch();
         if (cle && cle->ce_owner) {
                 void *cookie;
-                LASSERT(cle->ce_owner == cfs_current());
+                LASSERT(cle->ce_owner == (void *) (long) cfs_current()->pid);
                 cookie = cfs_hash_del(cl_env_hash, cle->ce_owner,
-                                         &cle->ce_node);
+                                      &cle->ce_node);
                 cle->ce_owner = NULL;
                 LASSERT(cookie == cle);
         }
@@ -748,7 +751,7 @@ struct lu_env *cl_env_peek(int *refcheck)
                 env = &cle->ce_lu;
                 *refcheck = ++cle->ce_ref;
         }
-        CDEBUG(D_OTHER, "%i@%p\n", cle ? cle->ce_ref : 0, cle);
+        CDEBUG(D_OTHER, "%d@%p\n", cle ? cle->ce_ref : 0, cle);
         return env;
 }
 EXPORT_SYMBOL(cl_env_peek);
@@ -779,7 +782,7 @@ struct lu_env *cl_env_get(int *refcheck)
                         cle = cl_env_container(env);
                         cl_env_attach(cle);
                         *refcheck = cle->ce_ref;
-                        CDEBUG(D_OTHER, "%i@%p\n", cle->ce_ref, cle);
+                        CDEBUG(D_OTHER, "%d@%p\n", cle->ce_ref, cle);
                 }
         }
         return env;
@@ -802,7 +805,7 @@ struct lu_env *cl_env_alloc(int *refcheck, __u32 tags)
 
                 cle = cl_env_container(env);
                 *refcheck = cle->ce_ref;
-                CDEBUG(D_OTHER, "%i@%p\n", cle->ce_ref, cle);
+                CDEBUG(D_OTHER, "%d@%p\n", cle->ce_ref, cle);
         }
         return env;
 }
@@ -858,7 +861,7 @@ void cl_env_put(struct lu_env *env, int *refcheck)
         LASSERT(cle->ce_ref > 0);
         LASSERT(ergo(refcheck != NULL, cle->ce_ref == *refcheck));
 
-        CDEBUG(D_OTHER, "%i@%p\n", cle->ce_ref, cle);
+        CDEBUG(D_OTHER, "%d@%p\n", cle->ce_ref, cle);
         if (--cle->ce_ref == 0) {
                 CL_ENV_DEC(cs_busy);
                 cl_env_detach(cle);
@@ -919,7 +922,7 @@ void cl_env_implant(struct lu_env *env, int *refcheck)
 
         cl_env_attach(cle);
         cl_env_get(refcheck);
-        CDEBUG(D_OTHER, "%i@%p\n", cle->ce_ref, cle);
+        CDEBUG(D_OTHER, "%d@%p\n", cle->ce_ref, cle);
 }
 EXPORT_SYMBOL(cl_env_implant);
 
@@ -932,7 +935,7 @@ void cl_env_unplant(struct lu_env *env, int *refcheck)
 
         LASSERT(cle->ce_ref > 1);
 
-        CDEBUG(D_OTHER, "%i@%p\n", cle->ce_ref, cle);
+        CDEBUG(D_OTHER, "%d@%p\n", cle->ce_ref, cle);
 
         cl_env_detach(cle);
         cl_env_put(env, refcheck);