Whamcloud - gitweb
b=21938 use req->rq_set itself during recovery
[fs/lustre-release.git] / lustre / include / class_hash.h
index 980e784..06cb691 100644 (file)
@@ -59,7 +59,7 @@ typedef struct lustre_hash {
         int                         lh_flags;       /* hash flags */
         atomic_t                    lh_count;       /* current entries */
         atomic_t                    lh_rehash_count;/* resize count */
-        struct lustre_hash_bucket  *lh_buckets;     /* hash buckets */
+        struct lustre_hash_bucket **lh_buckets;     /* hash buckets */
         struct lustre_hash_ops     *lh_ops;         /* hash operations */
         rwlock_t                    lh_rwlock;      /* lustre_hash */
         char                        lh_name[LUSTRE_MAX_HASH_NAME];
@@ -96,11 +96,9 @@ lh_key(lustre_hash_t *lh, struct hlist_node *hnode)
         LASSERT(lh);
         LASSERT(hnode);
         LASSERT(LHO(lh));
+        LASSERT(LHP(lh, key));
 
-        if (LHP(lh, key))
-                return LHP(lh, key)(hnode);
-
-        return NULL;
+        return LHP(lh, key)(hnode);
 }
 
 /* Returns 1 on a match,
@@ -180,7 +178,7 @@ __lustre_hash_bucket_validate(lustre_hash_t *lh, lustre_hash_bucket_t *lhb,
 
         if (unlikely(lh->lh_flags & LH_DEBUG)) {
                 i = lh_hash(lh, lh_key(lh, hnode), lh->lh_cur_mask);
-                LASSERT(&lh->lh_buckets[i] == lhb);
+                LASSERT(lh->lh_buckets[i] == lhb);
         }
 }
 
@@ -223,8 +221,22 @@ __lustre_hash_bucket_del(lustre_hash_t *lh,
         return lh_put(lh, hnode);
 }
 
+/* Some hash init argument constants */
+#define HASH_POOLS_CUR_BITS 3
+#define HASH_POOLS_MAX_BITS 7
+#define HASH_UUID_CUR_BITS 7
+#define HASH_UUID_MAX_BITS 12
+#define HASH_NID_CUR_BITS 7
+#define HASH_NID_MAX_BITS 12
+#define HASH_NID_STATS_CUR_BITS 7
+#define HASH_NID_STATS_MAX_BITS 12
+#define HASH_LQS_CUR_BITS 7
+#define HASH_LQS_MAX_BITS 12
+#define HASH_CONN_CUR_BITS 5
+#define HASH_CONN_MAX_BITS 15
+
 /* Hash init/cleanup functions */
-lustre_hash_t *lustre_hash_init(char *name, unsigned int cur_bits, 
+lustre_hash_t *lustre_hash_init(char *name, unsigned int cur_bits,
                                 unsigned int max_bits,
                                 lustre_hash_ops_t *ops, int flags);
 void lustre_hash_exit(lustre_hash_t *lh);
@@ -240,6 +252,8 @@ void *lustre_hash_findadd_unique(lustre_hash_t *lh, void *key,
 /* Hash deletion functions */
 void *lustre_hash_del(lustre_hash_t *lh, void *key, struct hlist_node *hnode);
 void *lustre_hash_del_key(lustre_hash_t *lh, void *key);
+typedef int (*lh_cond_opt_cb)(void *obj, void *data);
+void lustre_hash_cond_del(lustre_hash_t *lh, lh_cond_opt_cb, void *data);
 
 /* Hash lookup/for_each functions */
 void *lustre_hash_lookup(lustre_hash_t *lh, void *key);
@@ -250,9 +264,9 @@ void lustre_hash_for_each_empty(lustre_hash_t *lh, lh_for_each_cb, void *data);
 void lustre_hash_for_each_key(lustre_hash_t *lh, void *key,
                               lh_for_each_cb, void *data);
 
-/* 
+/*
  * Rehash - Theta is calculated to be the average chained
- * hash depth assuming a perfectly uniform hash funcion. 
+ * hash depth assuming a perfectly uniform hash funcion.
  */
 int lustre_hash_rehash(lustre_hash_t *lh, int bits);
 void lustre_hash_rehash_key(lustre_hash_t *lh, void *old_key,
@@ -270,7 +284,7 @@ static inline int __lustre_hash_theta_int(int theta)
 /* Return a fractional value between 0 and 999 */
 static inline int __lustre_hash_theta_frac(int theta)
 {
-        return ((theta * 1000) >> LH_THETA_BITS) - 
+        return ((theta * 1000) >> LH_THETA_BITS) -
                (__lustre_hash_theta_int(theta) * 1000);
 }
 
@@ -332,7 +346,13 @@ lh_u64_hash(__u64 key, unsigned mask)
 #define lh_for_each_bucket(lh, lhb, pos)         \
         for (pos = 0;                            \
              pos <= lh->lh_cur_mask &&           \
-             ({ lhb = &lh->lh_buckets[i]; 1; }); \
+             (lhb = lh->lh_buckets[pos]);       \
+             pos++)
+
+#define lh_for_each_bucket_restart(lh, lhb, pos) \
+        for (/* pos=0 done once by caller */;    \
+             pos <= lh->lh_cur_mask &&           \
+             (lhb = lh->lh_buckets[pos]);       \
              pos++)
 
 #endif /* __CLASS_HASH_H */