Whamcloud - gitweb
New tag 2.15.63
[fs/lustre-release.git] / libcfs / include / libcfs / libcfs_hash.h
index 34ffdb1..6fe31a6 100644 (file)
@@ -39,6 +39,7 @@
 
 #include <linux/spinlock.h>
 #include <linux/workqueue.h>
+#include <linux/refcount.h>
 #include <libcfs/linux/linux-hash.h>
 
 /** disable debug */
@@ -233,7 +234,7 @@ struct cfs_hash {
        /** rehash workitem */
        struct work_struct              hs_rehash_work;
        /** refcount on this hash table */
-       atomic_t                        hs_refcount;
+       struct kref                     hs_refcount;
        /** rehash buckets-table */
        struct cfs_hash_bucket          **hs_rehash_buckets;
 #if CFS_HASH_DEBUG_LEVEL >= CFS_HASH_DEBUG_1
@@ -250,8 +251,8 @@ struct cfs_hash {
         /** workitem to output max depth */
        struct work_struct              hs_dep_work;
 #endif
-        /** name of htable */
-        char                        hs_name[0];
+       /** name of htable */
+       char                        hs_name[];
 };
 
 struct cfs_hash_lock_ops {
@@ -280,7 +281,8 @@ struct cfs_hash_hlist_ops {
 
 struct cfs_hash_ops {
        /** return hashed value from @key */
-       unsigned (*hs_hash)(struct cfs_hash *hs, const void *key, unsigned mask);
+       unsigned int (*hs_hash)(struct cfs_hash *hs, const void *key,
+                               const unsigned int bits);
        /** return key address of @hnode */
        void *   (*hs_key)(struct hlist_node *hnode);
        /** copy key from @hnode to @key */
@@ -443,10 +445,10 @@ cfs_hash_bkt_size(struct cfs_hash *hs)
                hs->hs_extra_bytes;
 }
 
-static inline unsigned
-cfs_hash_id(struct cfs_hash *hs, const void *key, unsigned mask)
+static inline unsigned int
+cfs_hash_id(struct cfs_hash *hs, const void *key, const unsigned int bits)
 {
-       return hs->hs_ops->hs_hash(hs, key, mask);
+       return hs->hs_ops->hs_hash(hs, key, bits);
 }
 
 static inline void *
@@ -609,10 +611,10 @@ void cfs_hash_bd_move_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd_old,
 
 static inline int
 cfs_hash_bd_dec_and_lock(struct cfs_hash *hs, struct cfs_hash_bd *bd,
-                        atomic_t *condition)
+                        refcount_t *condition)
 {
        LASSERT(cfs_hash_with_spin_bktlock(hs));
-       return atomic_dec_and_lock(condition, &bd->bd_bucket->hsb_lock.spin);
+       return refcount_dec_and_lock(condition, &bd->bd_bucket->hsb_lock.spin);
 }
 
 static inline struct hlist_head *
@@ -803,16 +805,16 @@ void cfs_hash_debug_str(struct cfs_hash *hs, struct seq_file *m);
  * Generic djb2 hash algorithm for character arrays.
  */
 static inline unsigned
-cfs_hash_djb2_hash(const void *key, size_t size, unsigned mask)
+cfs_hash_djb2_hash(const void *key, size_t size, const unsigned int bits)
 {
-        unsigned i, hash = 5381;
+       unsigned int i, hash = 5381;
 
-        LASSERT(key != NULL);
+       LASSERT(key != NULL);
 
-        for (i = 0; i < size; i++)
-                hash = hash * 33 + ((char *)key)[i];
+       for (i = 0; i < size; i++)
+               hash = hash * 33 + ((char *)key)[i];
 
-        return (hash & mask);
+       return (hash & ((1U << bits) - 1));
 }
 
 /** iterate over all buckets in @bds (array of struct cfs_hash_bd) */