aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Spelvin <linux@sciencehorizons.net>2016-05-20 13:31:33 -0400
committerGeorge Spelvin <linux@sciencehorizons.net>2016-05-28 15:42:50 -0400
commit917ea166f4672ec085f2cccc135c7c0eec72282c (patch)
tree8443e6afe3799bf2c50b3af7aee77de6b81623e8
parentfcfd2fbf22d2587196890103d41e3d554c47da0e (diff)
<linux/sunrpc/svcauth.h>: Define hash_str() in terms of hashlen_string()
Finally, the first use of previous two patches: eliminate the separate ad-hoc string hash functions in the sunrpc code. Now hash_str() is a wrapper around hash_string(), and hash_mem() is likewise a wrapper around full_name_hash(). Note that sunrpc code *does* call hash_mem() with a zero length, which is why the previous patch needed to handle that in full_name_hash(). (Thanks, Bruce, for finding that!) This also eliminates the only caller of hash_long which asks for more than 32 bits of output. The comment about the quality of hashlen_string() and full_name_hash() is jumping the gun by a few patches; they aren't very impressive now, but will be improved greatly later in the series. Signed-off-by: George Spelvin <linux@sciencehorizons.net> Tested-by: J. Bruce Fields <bfields@redhat.com> Acked-by: J. Bruce Fields <bfields@redhat.com> Cc: Jeff Layton <jlayton@poochiereds.net> Cc: linux-nfs@vger.kernel.org
-rw-r--r--include/linux/sunrpc/svcauth.h40
1 files changed, 9 insertions, 31 deletions
diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
index c00f53a4ccdd..91d5a5d6f52b 100644
--- a/include/linux/sunrpc/svcauth.h
+++ b/include/linux/sunrpc/svcauth.h
@@ -16,6 +16,7 @@
16#include <linux/sunrpc/cache.h> 16#include <linux/sunrpc/cache.h>
17#include <linux/sunrpc/gss_api.h> 17#include <linux/sunrpc/gss_api.h>
18#include <linux/hash.h> 18#include <linux/hash.h>
19#include <linux/stringhash.h>
19#include <linux/cred.h> 20#include <linux/cred.h>
20 21
21struct svc_cred { 22struct svc_cred {
@@ -165,41 +166,18 @@ extern int svcauth_unix_set_client(struct svc_rqst *rqstp);
165extern int unix_gid_cache_create(struct net *net); 166extern int unix_gid_cache_create(struct net *net);
166extern void unix_gid_cache_destroy(struct net *net); 167extern void unix_gid_cache_destroy(struct net *net);
167 168
168static inline unsigned long hash_str(char *name, int bits) 169/*
170 * The <stringhash.h> functions are good enough that we don't need to
171 * use hash_32() on them; just extracting the high bits is enough.
172 */
173static inline unsigned long hash_str(char const *name, int bits)
169{ 174{
170 unsigned long hash = 0; 175 return hashlen_hash(hashlen_string(name)) >> (32 - bits);
171 unsigned long l = 0;
172 int len = 0;
173 unsigned char c;
174 do {
175 if (unlikely(!(c = *name++))) {
176 c = (char)len; len = -1;
177 }
178 l = (l << 8) | c;
179 len++;
180 if ((len & (BITS_PER_LONG/8-1))==0)
181 hash = hash_long(hash^l, BITS_PER_LONG);
182 } while (len);
183 return hash >> (BITS_PER_LONG - bits);
184} 176}
185 177
186static inline unsigned long hash_mem(char *buf, int length, int bits) 178static inline unsigned long hash_mem(char const *buf, int length, int bits)
187{ 179{
188 unsigned long hash = 0; 180 return full_name_hash(buf, length) >> (32 - bits);
189 unsigned long l = 0;
190 int len = 0;
191 unsigned char c;
192 do {
193 if (len == length) {
194 c = (char)len; len = -1;
195 } else
196 c = *buf++;
197 l = (l << 8) | c;
198 len++;
199 if ((len & (BITS_PER_LONG/8-1))==0)
200 hash = hash_long(hash^l, BITS_PER_LONG);
201 } while (len);
202 return hash >> (BITS_PER_LONG - bits);
203} 181}
204 182
205#endif /* __KERNEL__ */ 183#endif /* __KERNEL__ */