Whamcloud - gitweb
LU-3963 libcfs: remove cfs_hash_long 68/9268/2
authorPeng Tao <bergwolf@gmail.com>
Fri, 14 Feb 2014 01:58:50 +0000 (09:58 +0800)
committerOleg Drokin <oleg.drokin@intel.com>
Sat, 22 Feb 2014 08:07:43 +0000 (08:07 +0000)
Replace the name with Linux defined hash_long.
The similar patch has already been submitted upstream.

Signed-off-by: Peng Tao <bergwolf@gmail.com>
Change-Id: Ia96bb703284ed4843c4433a1a50539d9c68ed6d1
Reviewed-on: http://review.whamcloud.com/9268
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Liang Zhen <liang.zhen@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
libcfs/include/libcfs/libcfs_hash.h
libcfs/include/libcfs/winnt/winnt-prim.h
lnet/include/lnet/lib-lnet.h
lnet/lnet/api-ni.c
lnet/lnet/lib-ptl.c
lustre/include/lustre_fid.h
lustre/ldlm/ldlm_resource.c
lustre/obdclass/lu_object.c
lustre/ptlrpc/gss/gss_svc_upcall.c

index 07a12f6..444053d 100644 (file)
@@ -65,8 +65,6 @@
 
 #if (defined __linux__ && defined __KERNEL__)
 #include <linux/hash.h>
-
-#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
 
index ffb604a..7d8147f 100644 (file)
@@ -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;
index 9cebc3a..f7d9ae0 100644 (file)
@@ -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 *
index eb220b3..7ba7a3d 100644 (file)
@@ -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;
index 4a96349..b7938e3 100644 (file)
@@ -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];
        }
 }
index 0978092..cf8ba16 100644 (file)
@@ -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);
 }
 
 /**
index dc870e9..ef21c69 100644 (file)
@@ -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)
index eeb01b0..489796a 100644 (file)
@@ -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)
index 7e6d21a..3e60767 100644 (file)
@@ -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,