diff options
author | Sage Weil <sage@newdream.net> | 2009-11-07 23:18:22 -0500 |
---|---|---|
committer | Sage Weil <sage@newdream.net> | 2009-11-07 23:18:22 -0500 |
commit | fb690390e305ea51e1883b105c7d3c52d7100ba5 (patch) | |
tree | c099a71133225b1d22bba976e93dc6ab92a08986 /fs/ceph/crush/hash.c | |
parent | 1654dd0cf5ee1827322aca156af7d96d757201c7 (diff) |
ceph: make CRUSH hash function a bucket property
Make the integer hash function a property of the bucket it is used on. This
allows us to gracefully add support for new hash functions without starting
from scatch.
Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'fs/ceph/crush/hash.c')
-rw-r--r-- | fs/ceph/crush/hash.c | 73 |
1 files changed, 68 insertions, 5 deletions
diff --git a/fs/ceph/crush/hash.c b/fs/ceph/crush/hash.c index b438c5d27816..5873aed694bf 100644 --- a/fs/ceph/crush/hash.c +++ b/fs/ceph/crush/hash.c | |||
@@ -1,5 +1,6 @@ | |||
1 | 1 | ||
2 | #include <linux/types.h> | 2 | #include <linux/types.h> |
3 | #include "hash.h" | ||
3 | 4 | ||
4 | /* | 5 | /* |
5 | * Robert Jenkins' function for mixing 32-bit values | 6 | * Robert Jenkins' function for mixing 32-bit values |
@@ -20,7 +21,7 @@ | |||
20 | 21 | ||
21 | #define crush_hash_seed 1315423911 | 22 | #define crush_hash_seed 1315423911 |
22 | 23 | ||
23 | __u32 crush_hash32(__u32 a) | 24 | static __u32 crush_hash32_rjenkins1(__u32 a) |
24 | { | 25 | { |
25 | __u32 hash = crush_hash_seed ^ a; | 26 | __u32 hash = crush_hash_seed ^ a; |
26 | __u32 b = a; | 27 | __u32 b = a; |
@@ -31,7 +32,7 @@ __u32 crush_hash32(__u32 a) | |||
31 | return hash; | 32 | return hash; |
32 | } | 33 | } |
33 | 34 | ||
34 | __u32 crush_hash32_2(__u32 a, __u32 b) | 35 | static __u32 crush_hash32_rjenkins1_2(__u32 a, __u32 b) |
35 | { | 36 | { |
36 | __u32 hash = crush_hash_seed ^ a ^ b; | 37 | __u32 hash = crush_hash_seed ^ a ^ b; |
37 | __u32 x = 231232; | 38 | __u32 x = 231232; |
@@ -42,7 +43,7 @@ __u32 crush_hash32_2(__u32 a, __u32 b) | |||
42 | return hash; | 43 | return hash; |
43 | } | 44 | } |
44 | 45 | ||
45 | __u32 crush_hash32_3(__u32 a, __u32 b, __u32 c) | 46 | static __u32 crush_hash32_rjenkins1_3(__u32 a, __u32 b, __u32 c) |
46 | { | 47 | { |
47 | __u32 hash = crush_hash_seed ^ a ^ b ^ c; | 48 | __u32 hash = crush_hash_seed ^ a ^ b ^ c; |
48 | __u32 x = 231232; | 49 | __u32 x = 231232; |
@@ -55,7 +56,7 @@ __u32 crush_hash32_3(__u32 a, __u32 b, __u32 c) | |||
55 | return hash; | 56 | return hash; |
56 | } | 57 | } |
57 | 58 | ||
58 | __u32 crush_hash32_4(__u32 a, __u32 b, __u32 c, __u32 d) | 59 | static __u32 crush_hash32_rjenkins1_4(__u32 a, __u32 b, __u32 c, __u32 d) |
59 | { | 60 | { |
60 | __u32 hash = crush_hash_seed ^ a ^ b ^ c ^ d; | 61 | __u32 hash = crush_hash_seed ^ a ^ b ^ c ^ d; |
61 | __u32 x = 231232; | 62 | __u32 x = 231232; |
@@ -69,7 +70,8 @@ __u32 crush_hash32_4(__u32 a, __u32 b, __u32 c, __u32 d) | |||
69 | return hash; | 70 | return hash; |
70 | } | 71 | } |
71 | 72 | ||
72 | __u32 crush_hash32_5(__u32 a, __u32 b, __u32 c, __u32 d, __u32 e) | 73 | static __u32 crush_hash32_rjenkins1_5(__u32 a, __u32 b, __u32 c, __u32 d, |
74 | __u32 e) | ||
73 | { | 75 | { |
74 | __u32 hash = crush_hash_seed ^ a ^ b ^ c ^ d ^ e; | 76 | __u32 hash = crush_hash_seed ^ a ^ b ^ c ^ d ^ e; |
75 | __u32 x = 231232; | 77 | __u32 x = 231232; |
@@ -84,3 +86,64 @@ __u32 crush_hash32_5(__u32 a, __u32 b, __u32 c, __u32 d, __u32 e) | |||
84 | crush_hashmix(y, e, hash); | 86 | crush_hashmix(y, e, hash); |
85 | return hash; | 87 | return hash; |
86 | } | 88 | } |
89 | |||
90 | |||
91 | __u32 crush_hash32(int type, __u32 a) | ||
92 | { | ||
93 | switch (type) { | ||
94 | case CRUSH_HASH_RJENKINS1: | ||
95 | return crush_hash32_rjenkins1(a); | ||
96 | default: | ||
97 | return 0; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | __u32 crush_hash32_2(int type, __u32 a, __u32 b) | ||
102 | { | ||
103 | switch (type) { | ||
104 | case CRUSH_HASH_RJENKINS1: | ||
105 | return crush_hash32_rjenkins1_2(a, b); | ||
106 | default: | ||
107 | return 0; | ||
108 | } | ||
109 | } | ||
110 | |||
111 | __u32 crush_hash32_3(int type, __u32 a, __u32 b, __u32 c) | ||
112 | { | ||
113 | switch (type) { | ||
114 | case CRUSH_HASH_RJENKINS1: | ||
115 | return crush_hash32_rjenkins1_3(a, b, c); | ||
116 | default: | ||
117 | return 0; | ||
118 | } | ||
119 | } | ||
120 | |||
121 | __u32 crush_hash32_4(int type, __u32 a, __u32 b, __u32 c, __u32 d) | ||
122 | { | ||
123 | switch (type) { | ||
124 | case CRUSH_HASH_RJENKINS1: | ||
125 | return crush_hash32_rjenkins1_4(a, b, c, d); | ||
126 | default: | ||
127 | return 0; | ||
128 | } | ||
129 | } | ||
130 | |||
131 | __u32 crush_hash32_5(int type, __u32 a, __u32 b, __u32 c, __u32 d, __u32 e) | ||
132 | { | ||
133 | switch (type) { | ||
134 | case CRUSH_HASH_RJENKINS1: | ||
135 | return crush_hash32_rjenkins1_5(a, b, c, d, e); | ||
136 | default: | ||
137 | return 0; | ||
138 | } | ||
139 | } | ||
140 | |||
141 | const char *crush_hash_name(int type) | ||
142 | { | ||
143 | switch (type) { | ||
144 | case CRUSH_HASH_RJENKINS1: | ||
145 | return "rjenkins1"; | ||
146 | default: | ||
147 | return "unknown"; | ||
148 | } | ||
149 | } | ||