diff options
| author | David Woodhouse <David.Woodhouse@intel.com> | 2008-08-19 14:21:57 -0400 |
|---|---|---|
| committer | Chris Mason <chris.mason@oracle.com> | 2008-09-25 11:04:06 -0400 |
| commit | 615f996fb8185a0bc02812ebd72cb77ded5645f1 (patch) | |
| tree | 0e97c4fd52b44d603e589e41c90892739e6f5a30 /fs | |
| parent | 76fcef19c40328499a2f6d59d76b72fd03d2cc82 (diff) | |
Switch btrfs_name_hash() to crc32c
Date: Tue, 19 Aug 2008 19:21:57 +0100
Using a 64-bit hash as the readdir cookie is just asking for trouble.
And gets it, when we try to export the file system by NFS.
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs')
| -rw-r--r-- | fs/btrfs/Makefile | 2 | ||||
| -rw-r--r-- | fs/btrfs/hash.c | 112 | ||||
| -rw-r--r-- | fs/btrfs/hash.h | 7 |
3 files changed, 7 insertions, 114 deletions
diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile index 75f8818cbfe..8213bba1de9 100644 --- a/fs/btrfs/Makefile +++ b/fs/btrfs/Makefile | |||
| @@ -3,7 +3,7 @@ ifneq ($(KERNELRELEASE),) | |||
| 3 | 3 | ||
| 4 | obj-m := btrfs.o | 4 | obj-m := btrfs.o |
| 5 | btrfs-y := super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \ | 5 | btrfs-y := super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \ |
| 6 | hash.o file-item.o inode-item.o inode-map.o disk-io.o \ | 6 | file-item.o inode-item.o inode-map.o disk-io.o \ |
| 7 | transaction.o bit-radix.o inode.o file.o tree-defrag.o \ | 7 | transaction.o bit-radix.o inode.o file.o tree-defrag.o \ |
| 8 | extent_map.o sysfs.o struct-funcs.o xattr.o ordered-data.o \ | 8 | extent_map.o sysfs.o struct-funcs.o xattr.o ordered-data.o \ |
| 9 | extent_io.o volumes.o async-thread.o ioctl.o locking.o orphan.o \ | 9 | extent_io.o volumes.o async-thread.o ioctl.o locking.o orphan.o \ |
diff --git a/fs/btrfs/hash.c b/fs/btrfs/hash.c deleted file mode 100644 index 21037cfca9b..00000000000 --- a/fs/btrfs/hash.c +++ /dev/null | |||
| @@ -1,112 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2007 Oracle. All rights reserved. | ||
| 3 | * | ||
| 4 | * This program is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU General Public | ||
| 6 | * License v2 as published by the Free Software Foundation. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 11 | * General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public | ||
| 14 | * License along with this program; if not, write to the | ||
| 15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
| 16 | * Boston, MA 021110-1307, USA. | ||
| 17 | */ | ||
| 18 | |||
| 19 | /* | ||
| 20 | * Original copy from: | ||
| 21 | * linux/fs/ext3/hash.c | ||
| 22 | * | ||
| 23 | * Copyright (C) 2002 by Theodore Ts'o | ||
| 24 | * | ||
| 25 | * This file is released under the GPL v2. | ||
| 26 | * | ||
| 27 | * This file may be redistributed under the terms of the GNU Public | ||
| 28 | * License. | ||
| 29 | */ | ||
| 30 | |||
| 31 | #include <linux/types.h> | ||
| 32 | #include "hash.h" | ||
| 33 | #define DELTA 0x9E3779B9 | ||
| 34 | |||
| 35 | static void TEA_transform(__u32 buf[2], __u32 const in[]) | ||
| 36 | { | ||
| 37 | __u32 sum = 0; | ||
| 38 | __u32 b0 = buf[0], b1 = buf[1]; | ||
| 39 | __u32 a = in[0], b = in[1], c = in[2], d = in[3]; | ||
| 40 | int n = 16; | ||
| 41 | |||
| 42 | do { | ||
| 43 | sum += DELTA; | ||
| 44 | b0 += ((b1 << 4)+a) ^ (b1+sum) ^ ((b1 >> 5)+b); | ||
| 45 | b1 += ((b0 << 4)+c) ^ (b0+sum) ^ ((b0 >> 5)+d); | ||
| 46 | } while(--n); | ||
| 47 | |||
| 48 | buf[0] += b0; | ||
| 49 | buf[1] += b1; | ||
| 50 | } | ||
| 51 | |||
| 52 | static void str2hashbuf(const char *msg, int len, __u32 *buf, int num) | ||
| 53 | { | ||
| 54 | __u32 pad, val; | ||
| 55 | int i; | ||
| 56 | |||
| 57 | pad = (__u32)len | ((__u32)len << 8); | ||
| 58 | pad |= pad << 16; | ||
| 59 | |||
| 60 | val = pad; | ||
| 61 | if (len > num*4) | ||
| 62 | len = num * 4; | ||
| 63 | for (i=0; i < len; i++) { | ||
| 64 | if ((i % 4) == 0) | ||
| 65 | val = pad; | ||
| 66 | val = msg[i] + (val << 8); | ||
| 67 | if ((i % 4) == 3) { | ||
| 68 | *buf++ = val; | ||
| 69 | val = pad; | ||
| 70 | num--; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | if (--num >= 0) | ||
| 74 | *buf++ = val; | ||
| 75 | while (--num >= 0) | ||
| 76 | *buf++ = pad; | ||
| 77 | } | ||
| 78 | |||
| 79 | u64 btrfs_name_hash(const char *name, int len) | ||
| 80 | { | ||
| 81 | __u32 hash; | ||
| 82 | __u32 minor_hash = 0; | ||
| 83 | const char *p; | ||
| 84 | __u32 in[8], buf[4]; | ||
| 85 | u64 hash_result; | ||
| 86 | |||
| 87 | if (len == 1 && *name == '.') { | ||
| 88 | return 1; | ||
| 89 | } else if (len == 2 && name[0] == '.' && name[1] == '.') { | ||
| 90 | return 2; | ||
| 91 | } | ||
| 92 | |||
| 93 | /* Initialize the default seed for the hash checksum functions */ | ||
| 94 | buf[0] = 0x67452301; | ||
| 95 | buf[1] = 0xefcdab89; | ||
| 96 | buf[2] = 0x98badcfe; | ||
| 97 | buf[3] = 0x10325476; | ||
| 98 | |||
| 99 | p = name; | ||
| 100 | while (len > 0) { | ||
| 101 | str2hashbuf(p, len, in, 4); | ||
| 102 | TEA_transform(buf, in); | ||
| 103 | len -= 16; | ||
| 104 | p += 16; | ||
| 105 | } | ||
| 106 | hash = buf[0]; | ||
| 107 | minor_hash = buf[1]; | ||
| 108 | hash_result = buf[0]; | ||
| 109 | hash_result <<= 32; | ||
| 110 | hash_result |= buf[1]; | ||
| 111 | return hash_result; | ||
| 112 | } | ||
diff --git a/fs/btrfs/hash.h b/fs/btrfs/hash.h index 868ee17ca77..2a020b27676 100644 --- a/fs/btrfs/hash.h +++ b/fs/btrfs/hash.h | |||
| @@ -18,5 +18,10 @@ | |||
| 18 | 18 | ||
| 19 | #ifndef __HASH__ | 19 | #ifndef __HASH__ |
| 20 | #define __HASH__ | 20 | #define __HASH__ |
| 21 | u64 btrfs_name_hash(const char *name, int len); | 21 | |
| 22 | #include "crc32c.h" | ||
| 23 | static inline u64 btrfs_name_hash(const char *name, int len) | ||
| 24 | { | ||
| 25 | return btrfs_crc32c((u32)~1, name, len); | ||
| 26 | } | ||
| 22 | #endif | 27 | #endif |
