Skip to content

Commit

Permalink
<linux/sunrpc/svcauth.h>: Define hash_str() in terms of hashlen_string()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Tested-by: J. Bruce Fields <[email protected]>
Acked-by: J. Bruce Fields <[email protected]>
Cc: Jeff Layton <[email protected]>
Cc: [email protected]
  • Loading branch information
George Spelvin committed May 28, 2016
1 parent fcfd2fb commit 917ea16
Showing 1 changed file with 9 additions and 31 deletions.
40 changes: 9 additions & 31 deletions include/linux/sunrpc/svcauth.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <linux/sunrpc/cache.h>
#include <linux/sunrpc/gss_api.h>
#include <linux/hash.h>
#include <linux/stringhash.h>
#include <linux/cred.h>

struct svc_cred {
Expand Down Expand Up @@ -165,41 +166,18 @@ extern int svcauth_unix_set_client(struct svc_rqst *rqstp);
extern int unix_gid_cache_create(struct net *net);
extern void unix_gid_cache_destroy(struct net *net);

static inline unsigned long hash_str(char *name, int bits)
/*
* The <stringhash.h> functions are good enough that we don't need to
* use hash_32() on them; just extracting the high bits is enough.
*/
static inline unsigned long hash_str(char const *name, int bits)
{
unsigned long hash = 0;
unsigned long l = 0;
int len = 0;
unsigned char c;
do {
if (unlikely(!(c = *name++))) {
c = (char)len; len = -1;
}
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);
return hashlen_hash(hashlen_string(name)) >> (32 - bits);
}

static inline unsigned long hash_mem(char *buf, int length, int bits)
static inline unsigned long hash_mem(char const *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 = hash_long(hash^l, BITS_PER_LONG);
} while (len);
return hash >> (BITS_PER_LONG - bits);
return full_name_hash(buf, length) >> (32 - bits);
}

#endif /* __KERNEL__ */
Expand Down

0 comments on commit 917ea16

Please sign in to comment.