From 976c0abd4efab4f56cf4b21b940eb1b976c37372 Mon Sep 17 00:00:00 2001 From: Peng Tao Date: Fri, 14 Feb 2014 09:58:50 +0800 Subject: [PATCH] LU-3963 libcfs: remove cfs_hash_long Replace the name with Linux defined hash_long. The similar patch has already been submitted upstream. Signed-off-by: Peng Tao Change-Id: Ia96bb703284ed4843c4433a1a50539d9c68ed6d1 Reviewed-on: http://review.whamcloud.com/9268 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Liang Zhen Reviewed-by: Andreas Dilger --- libcfs/include/libcfs/libcfs_hash.h | 6 ++--- libcfs/include/libcfs/winnt/winnt-prim.h | 2 +- lnet/include/lnet/lib-lnet.h | 2 +- lnet/lnet/api-ni.c | 2 +- lnet/lnet/lib-ptl.c | 2 +- lustre/include/lustre_fid.h | 6 ++--- lustre/ldlm/ldlm_resource.c | 28 +++++++++++----------- lustre/obdclass/lu_object.c | 22 +++++++++--------- lustre/ptlrpc/gss/gss_svc_upcall.c | 40 ++++++++++++++++---------------- 9 files changed, 54 insertions(+), 56 deletions(-) diff --git a/libcfs/include/libcfs/libcfs_hash.h b/libcfs/include/libcfs/libcfs_hash.h index 07a12f6..444053d 100644 --- a/libcfs/include/libcfs/libcfs_hash.h +++ b/libcfs/include/libcfs/libcfs_hash.h @@ -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 diff --git a/libcfs/include/libcfs/winnt/winnt-prim.h b/libcfs/include/libcfs/winnt/winnt-prim.h index ffb604a..7d8147f 100644 --- a/libcfs/include/libcfs/winnt/winnt-prim.h +++ b/libcfs/include/libcfs/winnt/winnt-prim.h @@ -754,7 +754,7 @@ extern struct module libcfs_global_module; #define GOLDEN_RATIO_PRIME_32 0x9e370001UL #if 0 /* defined in libcfs/libcfs_hash.h */ -static inline u32 cfs_hash_long(u32 val, unsigned int bits) +static inline u32 hash_long(u32 val, unsigned int bits) { /* On some cpus multiply is faster, on others gcc will do shifts */ u32 hash = val * GOLDEN_RATIO_PRIME_32; diff --git a/lnet/include/lnet/lib-lnet.h b/lnet/include/lnet/lib-lnet.h index 9cebc3a..f7d9ae00 100644 --- a/lnet/include/lnet/lib-lnet.h +++ b/lnet/include/lnet/lib-lnet.h @@ -697,7 +697,7 @@ void lnet_ni_free(lnet_ni_t *ni); static inline int lnet_nid2peerhash(lnet_nid_t nid) { - return cfs_hash_long(nid, LNET_PEER_HASH_BITS); + return hash_long(nid, LNET_PEER_HASH_BITS); } static inline cfs_list_t * diff --git a/lnet/lnet/api-ni.c b/lnet/lnet/api-ni.c index eb220b3..7ba7a3d 100644 --- a/lnet/lnet/api-ni.c +++ b/lnet/lnet/api-ni.c @@ -892,7 +892,7 @@ lnet_nid_cpt_hash(lnet_nid_t nid, unsigned int number) if (number == 1) return 0; - val = cfs_hash_long(key, LNET_CPT_BITS); + val = hash_long(key, LNET_CPT_BITS); /* NB: LNET_CP_NUMBER doesn't have to be PO2 */ if (val < number) return val; diff --git a/lnet/lnet/lib-ptl.c b/lnet/lnet/lib-ptl.c index 4a96349..b7938e3 100644 --- a/lnet/lnet/lib-ptl.c +++ b/lnet/lnet/lib-ptl.c @@ -366,7 +366,7 @@ lnet_mt_match_head(struct lnet_match_table *mtable, unsigned long hash = mbits + id.nid + id.pid; LASSERT(lnet_ptl_is_unique(ptl)); - hash = cfs_hash_long(hash, LNET_MT_HASH_BITS); + hash = hash_long(hash, LNET_MT_HASH_BITS); return &mtable->mt_mhash[hash]; } } diff --git a/lustre/include/lustre_fid.h b/lustre/include/lustre_fid.h index 0978092..cf8ba16 100644 --- a/lustre/include/lustre_fid.h +++ b/lustre/include/lustre_fid.h @@ -676,9 +676,9 @@ static inline __u64 fid_flatten(const struct lu_fid *fid) static inline __u32 fid_hash(const struct lu_fid *f, int bits) { - /* all objects with same id and different versions will belong to same - * collisions list. */ - return cfs_hash_long(fid_flatten(f), bits); + /* all objects with same id and different versions will belong to same + * collisions list. */ + return hash_long(fid_flatten(f), bits); } /** diff --git a/lustre/ldlm/ldlm_resource.c b/lustre/ldlm/ldlm_resource.c index dc870e9..ef21c69 100644 --- a/lustre/ldlm/ldlm_resource.c +++ b/lustre/ldlm/ldlm_resource.c @@ -419,22 +419,22 @@ static unsigned ldlm_res_hop_fid_hash(cfs_hash_t *hs, fid.f_oid = (__u32)id->name[LUSTRE_RES_ID_VER_OID_OFF]; fid.f_ver = (__u32)(id->name[LUSTRE_RES_ID_VER_OID_OFF] >> 32); - hash = fid_flatten32(&fid); - hash += (hash >> 4) + (hash << 12); /* mixing oid and seq */ - if (id->name[LUSTRE_RES_ID_HSH_OFF] != 0) { - val = id->name[LUSTRE_RES_ID_HSH_OFF]; - hash += (val >> 5) + (val << 11); - } else { - val = fid_oid(&fid); - } - hash = cfs_hash_long(hash, hs->hs_bkt_bits); - /* give me another random factor */ - hash -= cfs_hash_long((unsigned long)hs, val % 11 + 3); + hash = fid_flatten32(&fid); + hash += (hash >> 4) + (hash << 12); /* mixing oid and seq */ + if (id->name[LUSTRE_RES_ID_HSH_OFF] != 0) { + val = id->name[LUSTRE_RES_ID_HSH_OFF]; + hash += (val >> 5) + (val << 11); + } else { + val = fid_oid(&fid); + } + hash = hash_long(hash, hs->hs_bkt_bits); + /* give me another random factor */ + hash -= hash_long((unsigned long)hs, val % 11 + 3); - hash <<= hs->hs_cur_bits - hs->hs_bkt_bits; - hash |= ldlm_res_hop_hash(hs, key, CFS_HASH_NBKT(hs) - 1); + hash <<= hs->hs_cur_bits - hs->hs_bkt_bits; + hash |= ldlm_res_hop_hash(hs, key, CFS_HASH_NBKT(hs) - 1); - return hash & mask; + return hash & mask; } static void *ldlm_res_hop_key(cfs_hlist_node_t *hnode) diff --git a/lustre/obdclass/lu_object.c b/lustre/obdclass/lu_object.c index eeb01b0..489796a 100644 --- a/lustre/obdclass/lu_object.c +++ b/lustre/obdclass/lu_object.c @@ -935,22 +935,22 @@ static int lu_htable_order(void) } static unsigned lu_obj_hop_hash(cfs_hash_t *hs, - const void *key, unsigned mask) + const void *key, unsigned mask) { - struct lu_fid *fid = (struct lu_fid *)key; - __u32 hash; + struct lu_fid *fid = (struct lu_fid *)key; + __u32 hash; - hash = fid_flatten32(fid); - hash += (hash >> 4) + (hash << 12); /* mixing oid and seq */ - hash = cfs_hash_long(hash, hs->hs_bkt_bits); + hash = fid_flatten32(fid); + hash += (hash >> 4) + (hash << 12); /* mixing oid and seq */ + hash = hash_long(hash, hs->hs_bkt_bits); - /* give me another random factor */ - hash -= cfs_hash_long((unsigned long)hs, fid_oid(fid) % 11 + 3); + /* give me another random factor */ + hash -= hash_long((unsigned long)hs, fid_oid(fid) % 11 + 3); - hash <<= hs->hs_cur_bits - hs->hs_bkt_bits; - hash |= (fid_seq(fid) + fid_oid(fid)) & (CFS_HASH_NBKT(hs) - 1); + hash <<= hs->hs_cur_bits - hs->hs_bkt_bits; + hash |= (fid_seq(fid) + fid_oid(fid)) & (CFS_HASH_NBKT(hs) - 1); - return hash & mask; + return hash & mask; } static void *lu_obj_hop_object(cfs_hlist_node_t *hnode) diff --git a/lustre/ptlrpc/gss/gss_svc_upcall.c b/lustre/ptlrpc/gss/gss_svc_upcall.c index 7e6d21a..3e60767 100644 --- a/lustre/ptlrpc/gss/gss_svc_upcall.c +++ b/lustre/ptlrpc/gss/gss_svc_upcall.c @@ -90,26 +90,26 @@ __u64 gss_get_next_ctx_index(void) static inline unsigned long hash_mem(char *buf, int length, int bits) { - unsigned long hash = 0; - unsigned long l = 0; - int len = 0; - unsigned char c; - - do { - if (len == length) { - c = (char) len; - len = -1; - } else - c = *buf++; - - l = (l << 8) | c; - len++; - - if ((len & (BITS_PER_LONG/8-1)) == 0) - hash = cfs_hash_long(hash^l, BITS_PER_LONG); - } while (len); - - return hash >> (BITS_PER_LONG - bits); + unsigned long hash = 0; + unsigned long l = 0; + int len = 0; + unsigned char c; + + do { + if (len == length) { + c = (char) len; + len = -1; + } else + c = *buf++; + + l = (l << 8) | c; + len++; + + if ((len & (BITS_PER_LONG/8-1)) == 0) + hash = hash_long(hash^l, BITS_PER_LONG); + } while (len); + + return hash >> (BITS_PER_LONG - bits); } /* This compatibility can be removed once kernel 3.3 is used, -- 1.8.3.1