Commit ec6867b3 authored by Neil Brown's avatar Neil Brown Committed by Linus Torvalds

[PATCH] knfsd: Use hash_long from hash.h for hashing in rpc/svc caches.

It works much better than my little toy hash functions.
parent bb1eb94c
......@@ -24,6 +24,7 @@
#include <linux/dcache.h>
#include <linux/namei.h>
#include <linux/mount.h>
#include <linux/hash.h>
#include <linux/sunrpc/svc.h>
#include <linux/nfsd/nfsd.h>
......@@ -59,12 +60,9 @@ static inline int svc_expkey_hash(struct svc_expkey *item)
int hash = item->ek_fsidtype;
char * cp = (char*)item->ek_fsid;
int len = (item->ek_fsidtype==0)?8:4;
while (len--)
hash += *cp++;
cp = (char*)&item->ek_client;
len = sizeof(item->ek_client);
while (len--)
hash += *cp++;
hash ^= hash_mem(cp, len, EXPKEY_HASHBITS);
hash ^= hash_ptr(item->ek_client, EXPKEY_HASHBITS);
return hash & EXPKEY_HASHMASK;
}
......@@ -239,17 +237,12 @@ static struct cache_head *export_table[EXPORT_HASHMAX];
static inline int svc_export_hash(struct svc_export *item)
{
void *k[2];
unsigned char *cp;
int rv, i;
k[0] = item->ex_client;
k[1] = item->ex_dentry;
cp = (char*)k;
rv = 0;
for (i=0; i<sizeof(k); i++)
rv ^= cp[i];
return rv & EXPORT_HASHMASK;
int rv;
rv = hash_ptr(item->ex_client, EXPORT_HASHBITS);
rv ^= hash_ptr(item->ex_dentry, EXPORT_HASHBITS);
rv ^= hash_ptr(item->ex_mnt, EXPORT_HASHBITS);
return rv;
}
void svc_export_put(struct cache_head *item, struct cache_detail *cd)
......
......@@ -111,7 +111,11 @@ extern struct auth_domain *auth_unix_lookup(struct in_addr addr);
extern int auth_unix_forget_old(struct auth_domain *dom);
extern void svcauth_unix_purge(void);
extern int name_hash(char *name, int size);
extern int hash_mem(char *buf, int len, int bits);
static inline int hash_str(char *name, int bits)
{
return hash_mem(name, strlen(name), bits);
}
extern struct cache_detail auth_domain_cache, ip_map_cache;
......
......@@ -16,6 +16,7 @@
#include <linux/sunrpc/svcsock.h>
#include <linux/sunrpc/svcauth.h>
#include <linux/err.h>
#include <linux/hash.h>
#define RPCDBG_FACILITY RPCDBG_AUTH
......@@ -111,14 +112,22 @@ svc_auth_unregister(rpc_authflavor_t flavor)
* it will complain.
*/
int name_hash(char *name, int size)
int hash_mem(char *buf, int len, int bits)
{
int hash = 0;
while (*name) {
hash += *name;
name++;
unsigned long l;
while (len >= BITS_PER_LONG/8) {
l = *(unsigned long *)buf;
buf += BITS_PER_LONG/8;
len -= BITS_PER_LONG/8;
hash ^= hash_long(l, bits);
}
return hash % size;
if (len) {
l=0;
memcpy((char*)&l, buf, len);
hash ^= hash_long(l, bits);
}
return hash;
}
......@@ -161,7 +170,7 @@ void auth_domain_put(struct auth_domain *dom)
static inline int auth_domain_hash(struct auth_domain *item)
{
return name_hash(item->name, DN_HASHMAX);
return hash_str(item->name, DN_HASHBITS);
}
static inline int auth_domain_match(struct auth_domain *tmp, struct auth_domain *item)
{
......
......@@ -6,6 +6,7 @@
#include <linux/sunrpc/svcauth.h>
#include <linux/err.h>
#include <linux/seq_file.h>
#include <linux/hash.h>
#define RPCDBG_FACILITY RPCDBG_AUTH
......@@ -108,7 +109,8 @@ void ip_map_put(struct cache_head *item, struct cache_detail *cd)
static inline int ip_map_hash(struct ip_map *item)
{
return (name_hash(item->m_class, IP_HASHMAX) ^ item->m_addr.s_addr) & IP_HASHMASK;
return hash_str(item->m_class, IP_HASHBITS) ^
hash_long((unsigned long)item->m_addr.s_addr, IP_HASHBITS);
}
static inline int ip_map_match(struct ip_map *item, struct ip_map *tmp)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment