Whamcloud - gitweb
LU-669 mea.c unconditionally uses ldiskfs hashs
authorBrian Behlendorf <behlendorf1@llnl.gov>
Wed, 24 Aug 2011 18:18:07 +0000 (11:18 -0700)
committerOleg Drokin <green@whamcloud.com>
Mon, 12 Dec 2011 18:30:07 +0000 (13:30 -0500)
Remove the ldiskfs hash code from mea.c as described by
comment 15 in Lustre bugzilla 22410.  The MEA_MAGIC_HASH_SEGMENT
case has been replaced with a CERROR() which will indicate if
this ever occurs.

"Yes, the two level hashing function is implemented in this patch.
And there no ldiskfs hash dependency on client anymore, so those
ldiskfs hash function can be removed from mea.c"
    -- wangdi

This was originally filed as Lustre bugzilla 22410.

With the removal of this code the ldiskfsfs_dirhash() function
no longer has any consumers in obdclass.  It is now only used
by the ldiskfs osd.  Since this functionality was originally
copied from ldiskfs it makes sense to remove it entirely and
have the osd rely on the ldiskfs implementation.

Change-Id: I017918cad57fc0641ebbd9471cb5b5717c65dea2
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-on: http://review.whamcloud.com/1350
Reviewed-by: wangdi <di.wang@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
lustre/obdclass/Makefile.in
lustre/obdclass/autoMakefile.am
lustre/obdclass/hash.c [deleted file]
lustre/obdclass/mea.c

index 5096c62..2865539 100644 (file)
@@ -11,7 +11,7 @@ obdclass-all-objs := llog.o llog_cat.o llog_lvfs.o llog_obd.o llog_swab.o
 obdclass-all-objs += class_obd.o debug.o genops.o uuid.o llog_ioctl.o
 obdclass-all-objs += lprocfs_status.o lustre_handles.o lustre_peer.o
 obdclass-all-objs += statfs_pack.o obdo.o obd_config.o obd_mount.o mea.o
 obdclass-all-objs += class_obd.o debug.o genops.o uuid.o llog_ioctl.o
 obdclass-all-objs += lprocfs_status.o lustre_handles.o lustre_peer.o
 obdclass-all-objs += statfs_pack.o obdo.o obd_config.o obd_mount.o mea.o
-obdclass-all-objs += lu_object.o dt_object.o hash.o capa.o lu_time.o
+obdclass-all-objs += lu_object.o dt_object.o capa.o lu_time.o
 obdclass-all-objs += cl_object.o cl_page.o cl_lock.o cl_io.o lu_ref.o
 obdclass-all-objs += acl.o idmap.o
 obdclass-all-objs += md_local_object.o
 obdclass-all-objs += cl_object.o cl_page.o cl_lock.o cl_io.o lu_ref.o
 obdclass-all-objs += acl.o idmap.o
 obdclass-all-objs += md_local_object.o
index 54a3f20..9e15f8c 100644 (file)
@@ -36,7 +36,7 @@ obdclass_SOURCES := \
         lustre_handles.c lustre_peer.c obd_config.c            \
         obdo.c debug.c llog_ioctl.c uuid.c                      \
         llog_swab.c llog_obd.c llog.c llog_cat.c llog_lvfs.c    \
         lustre_handles.c lustre_peer.c obd_config.c            \
         obdo.c debug.c llog_ioctl.c uuid.c                      \
         llog_swab.c llog_obd.c llog.c llog_cat.c llog_lvfs.c    \
-        mea.c lu_object.c dt_object.c hash.c lu_ref.c
+        mea.c lu_object.c dt_object.c lu_ref.c
 
 obdclass_CFLAGS := $(EXTRA_KCFLAGS)
 obdclass_LDFLAGS := $(EXTRA_KLDFLAGS)
 
 obdclass_CFLAGS := $(EXTRA_KCFLAGS)
 obdclass_LDFLAGS := $(EXTRA_KLDFLAGS)
diff --git a/lustre/obdclass/hash.c b/lustre/obdclass/hash.c
deleted file mode 100644 (file)
index 5ad1e91..0000000
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * Copyright (C) 2002 by Theodore Ts'o
- *
- * This file is released under the GPL v2.
- *
- * This file may be redistributed under the terms of the GNU Public
- * License.
- */
-
-/*
- * obdclass/hash.c is copied from ldiskfs/hash.c.
- * ldiskfs is used by server only.
- * obdclass is shared by both client and server, it should not depend on ldiskfs.
- */
-
-#include <linux/fs.h>
-#include <linux/sched.h>
-#ifdef HAVE_SERVER_SUPPORT
-
-#ifdef HAVE_EXT4_LDISKFS
-#include <ldiskfs/ldiskfs_jbd2.h>
-#include <ldiskfs/ldiskfs.h>
-#else
-#include <linux/jbd.h>
-#include <linux/ldiskfs_fs.h>
-#endif
-
-#else
-# include <obd_class.h>
-#endif
-
-#define DELTA 0x9E3779B9
-
-
-static void TEA_transform(__u32 buf[4], __u32 const in[])
-{
-       __u32   sum = 0;
-       __u32   b0 = buf[0], b1 = buf[1];
-       __u32   a = in[0], b = in[1], c = in[2], d = in[3];
-       int     n = 16;
-
-       do {
-               sum += DELTA;
-               b0 += ((b1 << 4)+a) ^ (b1+sum) ^ ((b1 >> 5)+b);
-               b1 += ((b0 << 4)+c) ^ (b0+sum) ^ ((b0 >> 5)+d);
-       } while(--n);
-
-       buf[0] += b0;
-       buf[1] += b1;
-}
-
-/* F, G and H are basic MD4 functions: selection, majority, parity */
-#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
-#define G(x, y, z) (((x) & (y)) + (((x) ^ (y)) & (z)))
-#define H(x, y, z) ((x) ^ (y) ^ (z))
-
-/*
- * The generic round function.  The application is so specific that
- * we don't bother protecting all the arguments with parens, as is generally
- * good macro practice, in favor of extra legibility.
- * Rotation is separate from addition to prevent recomputation
- */
-#define ROUND(f, a, b, c, d, x, s)     \
-       (a += f(b, c, d) + x, a = (a << s) | (a >> (32-s)))
-#define K1 0
-#define K2 013240474631UL
-#define K3 015666365641UL
-
-/*
- * Basic cut-down MD4 transform.  Returns only 32 bits of result.
- */
-static void halfMD4Transform (__u32 buf[4], __u32 const in[])
-{
-       __u32   a = buf[0], b = buf[1], c = buf[2], d = buf[3];
-
-       /* Round 1 */
-       ROUND(F, a, b, c, d, in[0] + K1,  3);
-       ROUND(F, d, a, b, c, in[1] + K1,  7);
-       ROUND(F, c, d, a, b, in[2] + K1, 11);
-       ROUND(F, b, c, d, a, in[3] + K1, 19);
-       ROUND(F, a, b, c, d, in[4] + K1,  3);
-       ROUND(F, d, a, b, c, in[5] + K1,  7);
-       ROUND(F, c, d, a, b, in[6] + K1, 11);
-       ROUND(F, b, c, d, a, in[7] + K1, 19);
-
-       /* Round 2 */
-       ROUND(G, a, b, c, d, in[1] + K2,  3);
-       ROUND(G, d, a, b, c, in[3] + K2,  5);
-       ROUND(G, c, d, a, b, in[5] + K2,  9);
-       ROUND(G, b, c, d, a, in[7] + K2, 13);
-       ROUND(G, a, b, c, d, in[0] + K2,  3);
-       ROUND(G, d, a, b, c, in[2] + K2,  5);
-       ROUND(G, c, d, a, b, in[4] + K2,  9);
-       ROUND(G, b, c, d, a, in[6] + K2, 13);
-
-       /* Round 3 */
-       ROUND(H, a, b, c, d, in[3] + K3,  3);
-       ROUND(H, d, a, b, c, in[7] + K3,  9);
-       ROUND(H, c, d, a, b, in[2] + K3, 11);
-       ROUND(H, b, c, d, a, in[6] + K3, 15);
-       ROUND(H, a, b, c, d, in[1] + K3,  3);
-       ROUND(H, d, a, b, c, in[5] + K3,  9);
-       ROUND(H, c, d, a, b, in[0] + K3, 11);
-       ROUND(H, b, c, d, a, in[4] + K3, 15);
-
-       buf[0] += a;
-       buf[1] += b;
-       buf[2] += c;
-       buf[3] += d;
-}
-
-#undef ROUND
-#undef F
-#undef G
-#undef H
-#undef K1
-#undef K2
-#undef K3
-
-/* The old legacy hash */
-static __u32 dx_hack_hash (const char *name, int len)
-{
-       __u32 hash0 = 0x12a3fe2d, hash1 = 0x37abe8f9;
-       while (len--) {
-               __u32 hash = hash1 + (hash0 ^ (*name++ * 7152373));
-
-               if (hash & 0x80000000) hash -= 0x7fffffff;
-               hash1 = hash0;
-               hash0 = hash;
-       }
-       return (hash0 << 1);
-}
-
-static void str2hashbuf(const char *msg, int len, __u32 *buf, int num)
-{
-       __u32   pad, val;
-       int     i;
-
-       pad = (__u32)len | ((__u32)len << 8);
-       pad |= pad << 16;
-
-       val = pad;
-       if (len > num*4)
-               len = num * 4;
-       for (i=0; i < len; i++) {
-               if ((i % 4) == 0)
-                       val = pad;
-               val = msg[i] + (val << 8);
-               if ((i % 4) == 3) {
-                       *buf++ = val;
-                       val = pad;
-                       num--;
-               }
-       }
-       if (--num >= 0)
-               *buf++ = val;
-       while (--num >= 0)
-               *buf++ = pad;
-}
-
-/*
- * Returns the hash of a filename.  If len is 0 and name is NULL, then
- * this function can be used to test whether or not a hash version is
- * supported.
- *
- * The seed is an 4 longword (32 bits) "secret" which can be used to
- * uniquify a hash.  If the seed is all zero's, then some default seed
- * may be used.
- *
- * A particular hash version specifies whether or not the seed is
- * represented, and whether or not the returned hash is 32 bits or 64
- * bits.  32 bit hashes will return 0 for the minor hash.
- */
-int ldiskfsfs_dirhash(const char *name, int len, struct ldiskfs_dx_hash_info *hinfo)
-{
-       __u32   hash;
-       __u32   minor_hash = 0;
-       const char      *p;
-       int             i;
-       __u32           in[8], buf[4];
-
-       /* Initialize the default seed for the hash checksum functions */
-       buf[0] = 0x67452301;
-       buf[1] = 0xefcdab89;
-       buf[2] = 0x98badcfe;
-       buf[3] = 0x10325476;
-
-       /* Check to see if the seed is all zero's */
-       if (hinfo->seed) {
-               for (i=0; i < 4; i++) {
-                       if (hinfo->seed[i])
-                               break;
-               }
-               if (i < 4)
-                       memcpy(buf, hinfo->seed, sizeof(buf));
-       }
-
-       switch (hinfo->hash_version) {
-       case LDISKFS_DX_HASH_LEGACY:
-               hash = dx_hack_hash(name, len);
-               break;
-       case LDISKFS_DX_HASH_HALF_MD4:
-               p = name;
-               while (len > 0) {
-                       str2hashbuf(p, len, in, 8);
-                       halfMD4Transform(buf, in);
-                       len -= 32;
-                       p += 32;
-               }
-               minor_hash = buf[2];
-               hash = buf[1];
-               break;
-       case LDISKFS_DX_HASH_TEA:
-               p = name;
-               while (len > 0) {
-                       str2hashbuf(p, len, in, 4);
-                       TEA_transform(buf, in);
-                       len -= 16;
-                       p += 16;
-               }
-               hash = buf[0];
-               minor_hash = buf[1];
-               break;
-       default:
-               hinfo->hash = 0;
-               return -1;
-       }
-       hash = hash & ~1;
-       if (hash == (LDISKFS_HTREE_EOF << 1))
-               hash = (LDISKFS_HTREE_EOF-1) << 1;
-       hinfo->hash = hash;
-       hinfo->minor_hash = minor_hash;
-       return 0;
-}
index d3f06ee..ac85dad 100644 (file)
 #include <lprocfs_status.h>
 #include <lustre/lustre_idl.h>
 
 #include <lprocfs_status.h>
 #include <lustre/lustre_idl.h>
 
-#ifdef __KERNEL__
-
-#ifdef HAVE_SERVER_SUPPORT
-
-#ifdef HAVE_EXT4_LDISKFS
-#include <ldiskfs/ldiskfs_jbd2.h>
-#include <ldiskfs/ldiskfs.h>
-#else
-#include <linux/jbd.h>
-#include <linux/ldiskfs_fs.h>
-#endif
-
-#endif
-#endif
 static int mea_last_char_hash(int count, char *name, int namelen)
 {
         unsigned int c;
 static int mea_last_char_hash(int count, char *name, int namelen)
 {
         unsigned int c;
@@ -83,79 +69,6 @@ static int mea_all_chars_hash(int count, char *name, int namelen)
         return c;
 }
 
         return c;
 }
 
-#ifdef __KERNEL__
-/* This hash calculate method must be same as the lvar hash method */
-
-#define LVAR_HASH_SANDWICH  (0)
-#define LVAR_HASH_PREFIX    (0)
-
-static __u32 hash_build0(const char *name, int namelen)
-{
-        __u32 result;
-
-        if (namelen == 0)
-                return 0;
-        if (strncmp(name, ".", 1) == 0 && namelen == 1)
-                return 1;
-        if (strncmp(name, "..", 2) == 0 && namelen == 2)
-                return 2;
-
-        if (LVAR_HASH_PREFIX) {
-                result = 0;
-                strncpy((void *)&result,
-                        name, min(namelen, (int)sizeof result));
-        } else {
-                struct ldiskfs_dx_hash_info hinfo;
-
-                hinfo.hash_version = LDISKFS_DX_HASH_TEA;
-                hinfo.seed = 0;
-                ldiskfsfs_dirhash(name, namelen, &hinfo);
-                result = hinfo.hash;
-                if (LVAR_HASH_SANDWICH) {
-                        __u32 result2;
-
-                        hinfo.hash_version = LDISKFS_DX_HASH_TEA;
-                        hinfo.seed = 0;
-                        ldiskfsfs_dirhash(name, namelen, &hinfo);
-                        result2 = hinfo.hash;
-                        result = (0xfc000000 & result2) | (0x03ffffff & result);
-                }
-        }
-
-        return result;
-}
-
-enum {
-        HASH_GRAY_AREA = 1024
-};
-
-static __u32 hash_build(const char *name, int namelen)
-{
-        __u32 hash;
-
-        hash = (hash_build0(name, namelen) << 1) & MAX_HASH_SIZE_32;
-        if (hash > MAX_HASH_SIZE_32 - HASH_GRAY_AREA)
-                hash &= HASH_GRAY_AREA - 1;
-        return hash;
-}
-
-static int mea_hash_segment(int count, const char *name, int namelen)
-{
-        __u32 hash;
-
-        LASSERT(IS_PO2(MAX_HASH_SIZE_32 + 1));
-
-        hash = hash_build(name, namelen) / (MAX_HASH_SIZE_32 / count);
-        LASSERTF(hash < count, "hash %x count %d \n", hash, count);
-
-        return hash;
-}
-#else
-static int mea_hash_segment(int count, char *name, int namelen)
-{
-        return 0;
-}
-#endif
 int raw_name2idx(int hashtype, int count, const char *name, int namelen)
 {
         unsigned int c = 0;
 int raw_name2idx(int hashtype, int count, const char *name, int namelen)
 {
         unsigned int c = 0;
@@ -172,12 +85,12 @@ int raw_name2idx(int hashtype, int count, const char *name, int namelen)
                         c = mea_all_chars_hash(count, (char *)name, namelen);
                         break;
                 case MEA_MAGIC_HASH_SEGMENT:
                         c = mea_all_chars_hash(count, (char *)name, namelen);
                         break;
                 case MEA_MAGIC_HASH_SEGMENT:
-                        c = mea_hash_segment(count, (char *)name, namelen);
+                        CERROR("Unsupported hash type MEA_MAGIC_HASH_SEGMENT\n");
                         break;
                 default:
                         CERROR("Unknown hash type 0x%x\n", hashtype);
         }
                         break;
                 default:
                         CERROR("Unknown hash type 0x%x\n", hashtype);
         }
-       
+
         LASSERT(c < count);
         return c;
 }
         LASSERT(c < count);
         return c;
 }