X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=libcfs%2Finclude%2Flibcfs%2Flibcfs_hash.h;h=444053d691d54997e38f1557ef3020ab27050ba4;hb=976c0abd4efab4f56cf4b21b940eb1b976c37372;hp=52382ad2563b0f0d630b9d1b9405a82a2fa45fae;hpb=fff2c3277d4c4fe6aaa5d5c2085892a6543c4730;p=fs%2Flustre-release.git diff --git a/libcfs/include/libcfs/libcfs_hash.h b/libcfs/include/libcfs/libcfs_hash.h index 52382ad..444053d 100644 --- a/libcfs/include/libcfs/libcfs_hash.h +++ b/libcfs/include/libcfs/libcfs_hash.h @@ -1,6 +1,4 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * +/* * GPL HEADER START * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -28,6 +26,8 @@ /* * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2012, 2013, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -65,8 +65,6 @@ #if (defined __linux__ && defined __KERNEL__) #include - -#define cfs_hash_long(val, bits) hash_long(val, bits) #else /* Fast hashing routine for a long. (C) 2002 William Lee Irwin III, IBM */ @@ -81,7 +79,7 @@ #error Define CFS_GOLDEN_RATIO_PRIME for your wordsize. #endif -static inline unsigned long cfs_hash_long(unsigned long val, unsigned int bits) +static inline unsigned long hash_long(unsigned long val, unsigned int bits) { unsigned long hash = val; @@ -111,7 +109,7 @@ static inline unsigned long cfs_hash_long(unsigned long val, unsigned int bits) #if 0 static inline unsigned long hash_ptr(void *ptr, unsigned int bits) { - return cfs_hash_long((unsigned long)ptr, bits); + return hash_long((unsigned long)ptr, bits); } #endif @@ -133,8 +131,8 @@ struct cfs_hash_lock_ops; struct cfs_hash_hlist_ops; typedef union { - cfs_rwlock_t rw; /**< rwlock */ - cfs_spinlock_t spin; /**< spinlock */ + rwlock_t rw; /**< rwlock */ + spinlock_t spin; /**< spinlock */ } cfs_hash_lock_t; /** @@ -149,12 +147,12 @@ typedef union { * - some extra bytes (caller can require it while creating hash) */ typedef struct cfs_hash_bucket { - cfs_hash_lock_t hsb_lock; /**< bucket lock */ - __u32 hsb_count; /**< current entries */ - __u32 hsb_version; /**< change version */ - unsigned int hsb_index; /**< index of bucket */ - int hsb_depmax; /**< max depth on bucket */ - char hsb_head[0]; /**< hash-head array */ + cfs_hash_lock_t hsb_lock; /**< bucket lock */ + __u32 hsb_count; /**< current entries */ + __u32 hsb_version; /**< change version */ + unsigned int hsb_index; /**< index of bucket */ + int hsb_depmax; /**< max depth on bucket */ + long hsb_head[0]; /**< hash-head array */ } cfs_hash_bucket_t; /** @@ -272,12 +270,12 @@ typedef struct cfs_hash { /** hash list operations */ struct cfs_hash_hlist_ops *hs_hops; /** hash buckets-table */ - cfs_hash_bucket_t **hs_buckets; - /** total number of items on this hash-table */ - cfs_atomic_t hs_count; - /** hash flags, see cfs_hash_tag for detail */ - __u16 hs_flags; - /** # of extra-bytes for bucket, for user saving extended attributes */ + cfs_hash_bucket_t **hs_buckets; + /** total number of items on this hash-table */ + atomic_t hs_count; + /** hash flags, see cfs_hash_tag for detail */ + __u16 hs_flags; + /** # of extra-bytes for bucket, for user saving extended attributes */ __u16 hs_extra_bytes; /** wants to iterate */ __u8 hs_iterating; @@ -301,15 +299,15 @@ typedef struct cfs_hash { __u32 hs_rehash_count; /** # of iterators (caller of cfs_hash_for_each_*) */ __u32 hs_iterators; - /** rehash workitem */ - cfs_workitem_t hs_rehash_wi; - /** refcount on this hash table */ - cfs_atomic_t hs_refcount; - /** rehash buckets-table */ - cfs_hash_bucket_t **hs_rehash_buckets; + /** rehash workitem */ + cfs_workitem_t hs_rehash_wi; + /** refcount on this hash table */ + atomic_t hs_refcount; + /** rehash buckets-table */ + cfs_hash_bucket_t **hs_rehash_buckets; #if CFS_HASH_DEBUG_LEVEL >= CFS_HASH_DEBUG_1 /** serialize debug members */ - cfs_spinlock_t hs_dep_lock; + spinlock_t hs_dep_lock; /** max depth */ unsigned int hs_dep_max; /** id of the deepest bucket */ @@ -337,37 +335,40 @@ typedef struct cfs_hash_lock_ops { } cfs_hash_lock_ops_t; typedef struct cfs_hash_hlist_ops { - /** return hlist_head of hash-head of @bd */ - cfs_hlist_head_t *(*hop_hhead)(cfs_hash_t *hs, cfs_hash_bd_t *bd); - /** return hash-head size */ - int (*hop_hhead_size)(cfs_hash_t *hs); - /** add @hnode to hash-head of @bd */ - int (*hop_hnode_add)(cfs_hash_t *hs, - cfs_hash_bd_t *bd, cfs_hlist_node_t *hnode); - /** remove @hnode from hash-head of @bd */ - int (*hop_hnode_del)(cfs_hash_t *hs, - cfs_hash_bd_t *bd, cfs_hlist_node_t *hnode); + /** return hlist_head of hash-head of @bd */ + struct hlist_head *(*hop_hhead)(cfs_hash_t *hs, cfs_hash_bd_t *bd); + /** return hash-head size */ + int (*hop_hhead_size)(cfs_hash_t *hs); + /** add @hnode to hash-head of @bd */ + int (*hop_hnode_add)(cfs_hash_t *hs, cfs_hash_bd_t *bd, + struct hlist_node *hnode); + /** remove @hnode from hash-head of @bd */ + int (*hop_hnode_del)(cfs_hash_t *hs, cfs_hash_bd_t *bd, + struct hlist_node *hnode); } cfs_hash_hlist_ops_t; typedef struct cfs_hash_ops { - /** return hashed value from @key */ - unsigned (*hs_hash)(cfs_hash_t *hs, void *key, unsigned mask); - /** return key address of @hnode */ - void * (*hs_key)(cfs_hlist_node_t *hnode); - /** copy key from @hnode to @key */ - void (*hs_keycpy)(cfs_hlist_node_t *hnode, void *key); - /** compare @key with key of @hnode */ - int (*hs_keycmp)(void *key, cfs_hlist_node_t *hnode); - /** return object address of @hnode, i.e: container_of(...hnode) */ - void * (*hs_object)(cfs_hlist_node_t *hnode); - /** get refcount of item, always called with holding bucket-lock */ - void * (*hs_get)(cfs_hlist_node_t *hnode); - /** release refcount of item */ - void * (*hs_put)(cfs_hlist_node_t *hnode); - /** release refcount of item, always called with holding bucket-lock */ - void * (*hs_put_locked)(cfs_hlist_node_t *hnode); - /** it's called before removing of @hnode */ - void (*hs_exit)(cfs_hlist_node_t *hnode); + /** return hashed value from @key */ + unsigned (*hs_hash)(cfs_hash_t *hs, const void *key, unsigned mask); + /** return key address of @hnode */ + void * (*hs_key)(struct hlist_node *hnode); + /** copy key from @hnode to @key */ + void (*hs_keycpy)(struct hlist_node *hnode, void *key); + /** + * compare @key with key of @hnode + * returns 1 on a match + */ + int (*hs_keycmp)(const void *key, struct hlist_node *hnode); + /** return object address of @hnode, i.e: container_of(...hnode) */ + void * (*hs_object)(struct hlist_node *hnode); + /** get refcount of item, always called with holding bucket-lock */ + void (*hs_get)(cfs_hash_t *hs, struct hlist_node *hnode); + /** release refcount of item */ + void (*hs_put)(cfs_hash_t *hs, struct hlist_node *hnode); + /** release refcount of item, always called with holding bucket-lock */ + void (*hs_put_locked)(cfs_hash_t *hs, struct hlist_node *hnode); + /** it's called before removing of @hnode */ + void (*hs_exit)(cfs_hash_t *hs, struct hlist_node *hnode); } cfs_hash_ops_t; /** total number of buckets in @hs */ @@ -507,66 +508,66 @@ cfs_hash_bkt_size(cfs_hash_t *hs) #define CFS_HOP(hs, op) (hs)->hs_ops->hs_ ## op static inline unsigned -cfs_hash_id(cfs_hash_t *hs, void *key, unsigned mask) +cfs_hash_id(cfs_hash_t *hs, const void *key, unsigned mask) { - return CFS_HOP(hs, hash)(hs, key, mask); + return CFS_HOP(hs, hash)(hs, key, mask); } static inline void * -cfs_hash_key(cfs_hash_t *hs, cfs_hlist_node_t *hnode) +cfs_hash_key(cfs_hash_t *hs, struct hlist_node *hnode) { - return CFS_HOP(hs, key)(hnode); + return CFS_HOP(hs, key)(hnode); } static inline void -cfs_hash_keycpy(cfs_hash_t *hs, cfs_hlist_node_t *hnode, void *key) +cfs_hash_keycpy(cfs_hash_t *hs, struct hlist_node *hnode, void *key) { - if (CFS_HOP(hs, keycpy) != NULL) - CFS_HOP(hs, keycpy)(hnode, key); + if (CFS_HOP(hs, keycpy) != NULL) + CFS_HOP(hs, keycpy)(hnode, key); } /** * Returns 1 on a match, */ static inline int -cfs_hash_keycmp(cfs_hash_t *hs, void *key, cfs_hlist_node_t *hnode) +cfs_hash_keycmp(cfs_hash_t *hs, const void *key, struct hlist_node *hnode) { - return CFS_HOP(hs, keycmp)(key, hnode); + return CFS_HOP(hs, keycmp)(key, hnode); } static inline void * -cfs_hash_object(cfs_hash_t *hs, cfs_hlist_node_t *hnode) +cfs_hash_object(cfs_hash_t *hs, struct hlist_node *hnode) { - return CFS_HOP(hs, object)(hnode); + return CFS_HOP(hs, object)(hnode); } -static inline void * -cfs_hash_get(cfs_hash_t *hs, cfs_hlist_node_t *hnode) +static inline void +cfs_hash_get(cfs_hash_t *hs, struct hlist_node *hnode) { - return CFS_HOP(hs, get)(hnode); + return CFS_HOP(hs, get)(hs, hnode); } -static inline void * -cfs_hash_put_locked(cfs_hash_t *hs, cfs_hlist_node_t *hnode) +static inline void +cfs_hash_put_locked(cfs_hash_t *hs, struct hlist_node *hnode) { - LASSERT(CFS_HOP(hs, put_locked) != NULL); + LASSERT(CFS_HOP(hs, put_locked) != NULL); - return CFS_HOP(hs, put_locked)(hnode); + return CFS_HOP(hs, put_locked)(hs, hnode); } -static inline void * -cfs_hash_put(cfs_hash_t *hs, cfs_hlist_node_t *hnode) +static inline void +cfs_hash_put(cfs_hash_t *hs, struct hlist_node *hnode) { - LASSERT(CFS_HOP(hs, put) != NULL); + LASSERT(CFS_HOP(hs, put) != NULL); - return CFS_HOP(hs, put)(hnode); + return CFS_HOP(hs, put)(hs, hnode); } static inline void -cfs_hash_exit(cfs_hash_t *hs, cfs_hlist_node_t *hnode) +cfs_hash_exit(cfs_hash_t *hs, struct hlist_node *hnode) { - if (CFS_HOP(hs, exit)) - CFS_HOP(hs, exit)(hnode); + if (CFS_HOP(hs, exit)) + CFS_HOP(hs, exit)(hs, hnode); } static inline void cfs_hash_lock(cfs_hash_t *hs, int excl) @@ -579,6 +580,13 @@ static inline void cfs_hash_unlock(cfs_hash_t *hs, int excl) hs->hs_lops->hs_unlock(&hs->hs_lock, excl); } +static inline int cfs_hash_dec_and_lock(cfs_hash_t *hs, + atomic_t *condition) +{ + LASSERT(cfs_hash_with_no_bktlock(hs)); + return atomic_dec_and_lock(condition, &hs->hs_lock.spin); +} + static inline void cfs_hash_bd_lock(cfs_hash_t *hs, cfs_hash_bd_t *bd, int excl) { @@ -595,15 +603,27 @@ static inline void cfs_hash_bd_unlock(cfs_hash_t *hs, * operations on cfs_hash bucket (bd: bucket descriptor), * they are normally for hash-table without rehash */ -void cfs_hash_bd_get(cfs_hash_t *hs, void *key, cfs_hash_bd_t *bd); +void cfs_hash_bd_get(cfs_hash_t *hs, const void *key, cfs_hash_bd_t *bd); -static inline void cfs_hash_bd_get_and_lock(cfs_hash_t *hs, void *key, +static inline void cfs_hash_bd_get_and_lock(cfs_hash_t *hs, const void *key, cfs_hash_bd_t *bd, int excl) { cfs_hash_bd_get(hs, key, bd); cfs_hash_bd_lock(hs, bd, excl); } +static inline unsigned cfs_hash_bd_index_get(cfs_hash_t *hs, cfs_hash_bd_t *bd) +{ + return bd->bd_offset | (bd->bd_bucket->hsb_index << hs->hs_bkt_bits); +} + +static inline void cfs_hash_bd_index_set(cfs_hash_t *hs, + unsigned index, cfs_hash_bd_t *bd) +{ + bd->bd_bucket = hs->hs_buckets[index >> hs->hs_bkt_bits]; + bd->bd_offset = index & (CFS_HASH_BKT_NHLIST(hs) - 1U); +} + static inline void * cfs_hash_bd_extra_get(cfs_hash_t *hs, cfs_hash_bd_t *bd) { @@ -644,101 +664,103 @@ cfs_hash_bd_compare(cfs_hash_bd_t *bd1, cfs_hash_bd_t *bd2) } void cfs_hash_bd_add_locked(cfs_hash_t *hs, cfs_hash_bd_t *bd, - cfs_hlist_node_t *hnode); + struct hlist_node *hnode); void cfs_hash_bd_del_locked(cfs_hash_t *hs, cfs_hash_bd_t *bd, - cfs_hlist_node_t *hnode); + struct hlist_node *hnode); void cfs_hash_bd_move_locked(cfs_hash_t *hs, cfs_hash_bd_t *bd_old, - cfs_hash_bd_t *bd_new, cfs_hlist_node_t *hnode); + cfs_hash_bd_t *bd_new, struct hlist_node *hnode); static inline int cfs_hash_bd_dec_and_lock(cfs_hash_t *hs, cfs_hash_bd_t *bd, - cfs_atomic_t *condition) + atomic_t *condition) { - LASSERT(cfs_hash_with_spin_bktlock(hs)); - return cfs_atomic_dec_and_lock(condition, - &bd->bd_bucket->hsb_lock.spin); + LASSERT(cfs_hash_with_spin_bktlock(hs)); + return atomic_dec_and_lock(condition, &bd->bd_bucket->hsb_lock.spin); } -static inline cfs_hlist_head_t *cfs_hash_bd_hhead(cfs_hash_t *hs, +static inline struct hlist_head *cfs_hash_bd_hhead(cfs_hash_t *hs, cfs_hash_bd_t *bd) { - return hs->hs_hops->hop_hhead(hs, bd); + return hs->hs_hops->hop_hhead(hs, bd); } -cfs_hlist_node_t *cfs_hash_bd_lookup_locked(cfs_hash_t *hs, - cfs_hash_bd_t *bd, void *key); -cfs_hlist_node_t *cfs_hash_bd_findadd_locked(cfs_hash_t *hs, - cfs_hash_bd_t *bd, void *key, - cfs_hlist_node_t *hnode, - int insist_add); -cfs_hlist_node_t *cfs_hash_bd_finddel_locked(cfs_hash_t *hs, - cfs_hash_bd_t *bd, void *key, - cfs_hlist_node_t *hnode); +struct hlist_node *cfs_hash_bd_lookup_locked(cfs_hash_t *hs, cfs_hash_bd_t *bd, + const void *key); +struct hlist_node *cfs_hash_bd_peek_locked(cfs_hash_t *hs, cfs_hash_bd_t *bd, + const void *key); +struct hlist_node *cfs_hash_bd_findadd_locked(cfs_hash_t *hs, cfs_hash_bd_t *bd, + const void *key, + struct hlist_node *hnode, + int insist_add); +struct hlist_node *cfs_hash_bd_finddel_locked(cfs_hash_t *hs, cfs_hash_bd_t *bd, + const void *key, + struct hlist_node *hnode); /** * operations on cfs_hash bucket (bd: bucket descriptor), * they are safe for hash-table with rehash */ -void cfs_hash_dual_bd_get(cfs_hash_t *hs, void *key, cfs_hash_bd_t *bds); +void cfs_hash_dual_bd_get(cfs_hash_t *hs, const void *key, cfs_hash_bd_t *bds); void cfs_hash_dual_bd_lock(cfs_hash_t *hs, cfs_hash_bd_t *bds, int excl); void cfs_hash_dual_bd_unlock(cfs_hash_t *hs, cfs_hash_bd_t *bds, int excl); -static inline void cfs_hash_dual_bd_get_and_lock(cfs_hash_t *hs, void *key, - cfs_hash_bd_t *bds, int excl) +static inline void cfs_hash_dual_bd_get_and_lock(cfs_hash_t *hs, const void *key, + cfs_hash_bd_t *bds, int excl) { - cfs_hash_dual_bd_get(hs, key, bds); - cfs_hash_dual_bd_lock(hs, bds, excl); + cfs_hash_dual_bd_get(hs, key, bds); + cfs_hash_dual_bd_lock(hs, bds, excl); } -cfs_hlist_node_t *cfs_hash_dual_bd_lookup_locked(cfs_hash_t *hs, - cfs_hash_bd_t *bds, void *key); -cfs_hlist_node_t *cfs_hash_dual_bd_findadd_locked(cfs_hash_t *hs, - cfs_hash_bd_t *bds, void *key, - cfs_hlist_node_t *hnode, - int insist_add); -cfs_hlist_node_t *cfs_hash_dual_bd_finddel_locked(cfs_hash_t *hs, - cfs_hash_bd_t *bds, void *key, - cfs_hlist_node_t *hnode); +struct hlist_node * +cfs_hash_dual_bd_lookup_locked(cfs_hash_t *hs, cfs_hash_bd_t *bds, + const void *key); +struct hlist_node * +cfs_hash_dual_bd_findadd_locked(cfs_hash_t *hs, cfs_hash_bd_t *bds, + const void *key, struct hlist_node *hnode, + int insist_add); +struct hlist_node * +cfs_hash_dual_bd_finddel_locked(cfs_hash_t *hs, cfs_hash_bd_t *bds, + const void *key, struct hlist_node *hnode); /* Hash init/cleanup functions */ cfs_hash_t *cfs_hash_create(char *name, unsigned cur_bits, unsigned max_bits, - unsigned bkt_bits, unsigned extra_bytes, - unsigned min_theta, unsigned max_theta, - cfs_hash_ops_t *ops, unsigned flags); + unsigned bkt_bits, unsigned extra_bytes, + unsigned min_theta, unsigned max_theta, + cfs_hash_ops_t *ops, unsigned flags); cfs_hash_t *cfs_hash_getref(cfs_hash_t *hs); void cfs_hash_putref(cfs_hash_t *hs); /* Hash addition functions */ -void cfs_hash_add(cfs_hash_t *hs, void *key, - cfs_hlist_node_t *hnode); -int cfs_hash_add_unique(cfs_hash_t *hs, void *key, - cfs_hlist_node_t *hnode); -void *cfs_hash_findadd_unique(cfs_hash_t *hs, void *key, - cfs_hlist_node_t *hnode); +void cfs_hash_add(cfs_hash_t *hs, const void *key, + struct hlist_node *hnode); +int cfs_hash_add_unique(cfs_hash_t *hs, const void *key, + struct hlist_node *hnode); +void *cfs_hash_findadd_unique(cfs_hash_t *hs, const void *key, + struct hlist_node *hnode); /* Hash deletion functions */ -void *cfs_hash_del(cfs_hash_t *hs, void *key, cfs_hlist_node_t *hnode); -void *cfs_hash_del_key(cfs_hash_t *hs, void *key); +void *cfs_hash_del(cfs_hash_t *hs, const void *key, struct hlist_node *hnode); +void *cfs_hash_del_key(cfs_hash_t *hs, const void *key); /* Hash lookup/for_each functions */ #define CFS_HASH_LOOP_HOG 1024 typedef int (*cfs_hash_for_each_cb_t)(cfs_hash_t *hs, cfs_hash_bd_t *bd, - cfs_hlist_node_t *node, void *data); -void *cfs_hash_lookup(cfs_hash_t *hs, void *key); + struct hlist_node *node, void *data); +void *cfs_hash_lookup(cfs_hash_t *hs, const void *key); void cfs_hash_for_each(cfs_hash_t *hs, cfs_hash_for_each_cb_t, void *data); void cfs_hash_for_each_safe(cfs_hash_t *hs, cfs_hash_for_each_cb_t, void *data); -int cfs_hash_for_each_nolock(cfs_hash_t *hs, - cfs_hash_for_each_cb_t, void *data); -int cfs_hash_for_each_empty(cfs_hash_t *hs, - cfs_hash_for_each_cb_t, void *data); -void cfs_hash_for_each_key(cfs_hash_t *hs, void *key, - cfs_hash_for_each_cb_t, void *data); +int cfs_hash_for_each_nolock(cfs_hash_t *hs, cfs_hash_for_each_cb_t, + void *data); +int cfs_hash_for_each_empty(cfs_hash_t *hs, cfs_hash_for_each_cb_t, + void *data); +void cfs_hash_for_each_key(cfs_hash_t *hs, const void *key, + cfs_hash_for_each_cb_t, void *data); typedef int (*cfs_hash_cond_opt_cb_t)(void *obj, void *data); void cfs_hash_cond_del(cfs_hash_t *hs, cfs_hash_cond_opt_cb_t, void *data); void cfs_hash_hlist_for_each(cfs_hash_t *hs, unsigned hindex, - cfs_hash_for_each_cb_t, void *data); + cfs_hash_for_each_cb_t, void *data); int cfs_hash_is_empty(cfs_hash_t *hs); __u64 cfs_hash_size_get(cfs_hash_t *hs); @@ -749,39 +771,39 @@ __u64 cfs_hash_size_get(cfs_hash_t *hs); void cfs_hash_rehash_cancel_locked(cfs_hash_t *hs); void cfs_hash_rehash_cancel(cfs_hash_t *hs); int cfs_hash_rehash(cfs_hash_t *hs, int do_rehash); -void cfs_hash_rehash_key(cfs_hash_t *hs, void *old_key, - void *new_key, cfs_hlist_node_t *hnode); +void cfs_hash_rehash_key(cfs_hash_t *hs, const void *old_key, + void *new_key, struct hlist_node *hnode); #if CFS_HASH_DEBUG_LEVEL > CFS_HASH_DEBUG_1 /* Validate hnode references the correct key */ static inline void -cfs_hash_key_validate(cfs_hash_t *hs, void *key, - cfs_hlist_node_t *hnode) +cfs_hash_key_validate(cfs_hash_t *hs, const void *key, + struct hlist_node *hnode) { - LASSERT(cfs_hash_keycmp(hs, key, hnode)); + LASSERT(cfs_hash_keycmp(hs, key, hnode)); } /* Validate hnode is in the correct bucket */ static inline void cfs_hash_bucket_validate(cfs_hash_t *hs, cfs_hash_bd_t *bd, - cfs_hlist_node_t *hnode) + struct hlist_node *hnode) { - cfs_hash_bd_t bds[2]; + cfs_hash_bd_t bds[2]; - cfs_hash_dual_bd_get(hs, cfs_hash_key(hs, hnode), bds); - LASSERT(bds[0].bd_bucket == bd->bd_bucket || - bds[1].bd_bucket == bd->bd_bucket); + cfs_hash_dual_bd_get(hs, cfs_hash_key(hs, hnode), bds); + LASSERT(bds[0].bd_bucket == bd->bd_bucket || + bds[1].bd_bucket == bd->bd_bucket); } #else /* CFS_HASH_DEBUG_LEVEL > CFS_HASH_DEBUG_1 */ static inline void -cfs_hash_key_validate(cfs_hash_t *hs, void *key, - cfs_hlist_node_t *hnode) {} +cfs_hash_key_validate(cfs_hash_t *hs, const void *key, + struct hlist_node *hnode) {} static inline void cfs_hash_bucket_validate(cfs_hash_t *hs, cfs_hash_bd_t *bd, - cfs_hlist_node_t *hnode) {} + struct hlist_node *hnode) {} #endif /* CFS_HASH_DEBUG_LEVEL */ @@ -804,8 +826,8 @@ static inline int __cfs_hash_theta_frac(int theta) static inline int __cfs_hash_theta(cfs_hash_t *hs) { - return (cfs_atomic_read(&hs->hs_count) << - CFS_HASH_THETA_BITS) >> hs->hs_cur_bits; + return (atomic_read(&hs->hs_count) << + CFS_HASH_THETA_BITS) >> hs->hs_cur_bits; } static inline void __cfs_hash_set_theta(cfs_hash_t *hs, int min, int max) @@ -816,14 +838,19 @@ static inline void __cfs_hash_set_theta(cfs_hash_t *hs, int min, int max) } /* Generic debug formatting routines mainly for proc handler */ +#ifndef HAVE_ONLY_PROCFS_SEQ int cfs_hash_debug_header(char *str, int size); int cfs_hash_debug_str(cfs_hash_t *hs, char *str, int size); +#endif +struct seq_file; +int cfs_hash_debug_header_seq(struct seq_file *m); +int cfs_hash_debug_str_seq(cfs_hash_t *hs, struct seq_file *m); /* * Generic djb2 hash algorithm for character arrays. */ static inline unsigned -cfs_hash_djb2_hash(void *key, size_t size, unsigned mask) +cfs_hash_djb2_hash(const void *key, size_t size, unsigned mask) { unsigned i, hash = 5381; @@ -839,7 +866,7 @@ cfs_hash_djb2_hash(void *key, size_t size, unsigned mask) * Generic u32 hash algorithm. */ static inline unsigned -cfs_hash_u32_hash(__u32 key, unsigned mask) +cfs_hash_u32_hash(const __u32 key, unsigned mask) { return ((key * CFS_GOLDEN_RATIO_PRIME_32) & mask); } @@ -848,7 +875,7 @@ cfs_hash_u32_hash(__u32 key, unsigned mask) * Generic u64 hash algorithm. */ static inline unsigned -cfs_hash_u64_hash(__u64 key, unsigned mask) +cfs_hash_u64_hash(const __u64 key, unsigned mask) { return ((unsigned)(key * CFS_GOLDEN_RATIO_PRIME_64) & mask); }