Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 114326
b: refs/heads/master
c: ede2fea
h: refs/heads/master
v: v3
  • Loading branch information
Chuck Lever authored and J. Bruce Fields committed Sep 29, 2008
1 parent f2c414f commit c8f0805
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 781b61a6f4ff94cb8c14cf598b547f5d5c490969
refs/heads/master: ede2fea099cf1dabe41e5b9563558bc7aee82248
49 changes: 43 additions & 6 deletions trunk/fs/lockd/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#define NLMDBG_FACILITY NLMDBG_HOSTCACHE
#define NLM_HOST_NRHASH 32
#define NLM_ADDRHASH(addr) (ntohl(addr) & (NLM_HOST_NRHASH-1))
#define NLM_HOST_REBIND (60 * HZ)
#define NLM_HOST_EXPIRE (300 * HZ)
#define NLM_HOST_COLLECT (120 * HZ)
Expand All @@ -40,6 +39,48 @@ static struct nsm_handle * nsm_find(const struct sockaddr_in *sin,
const char *hostname,
unsigned int hostname_len);

/*
* Hash function must work well on big- and little-endian platforms
*/
static unsigned int __nlm_hash32(const __be32 n)
{
unsigned int hash = (__force u32)n ^ ((__force u32)n >> 16);
return hash ^ (hash >> 8);
}

static unsigned int __nlm_hash_addr4(const struct sockaddr *sap)
{
const struct sockaddr_in *sin = (struct sockaddr_in *)sap;
return __nlm_hash32(sin->sin_addr.s_addr);
}

static unsigned int __nlm_hash_addr6(const struct sockaddr *sap)
{
const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
const struct in6_addr addr = sin6->sin6_addr;
return __nlm_hash32(addr.s6_addr32[0]) ^
__nlm_hash32(addr.s6_addr32[1]) ^
__nlm_hash32(addr.s6_addr32[2]) ^
__nlm_hash32(addr.s6_addr32[3]);
}

static unsigned int nlm_hash_address(const struct sockaddr *sap)
{
unsigned int hash;

switch (sap->sa_family) {
case AF_INET:
hash = __nlm_hash_addr4(sap);
break;
case AF_INET6:
hash = __nlm_hash_addr6(sap);
break;
default:
hash = 0;
}
return hash & (NLM_HOST_NRHASH - 1);
}

static void nlm_clear_port(struct sockaddr *sap)
{
switch (sap->sa_family) {
Expand Down Expand Up @@ -92,16 +133,12 @@ static struct nlm_host *nlm_lookup_host(int server,
struct hlist_node *pos;
struct nlm_host *host;
struct nsm_handle *nsm = NULL;
int hash;

dprintk("lockd: nlm_lookup_host(proto=%d, vers=%u,"
" my role is %s, hostname=%.*s)\n",
proto, version, server ? "server" : "client",
hostname_len, hostname ? hostname : "<none>");

hash = NLM_ADDRHASH(sin->sin_addr.s_addr);

/* Lock hash table */
mutex_lock(&nlm_host_mutex);

if (time_after_eq(jiffies, next_gc))
Expand All @@ -114,7 +151,7 @@ static struct nlm_host *nlm_lookup_host(int server,
* different NLM rpc_clients into one single nlm_host object.
* This would allow us to have one nlm_host per address.
*/
chain = &nlm_hosts[hash];
chain = &nlm_hosts[nlm_hash_address((struct sockaddr *)sin)];
hlist_for_each_entry(host, pos, chain, h_hash) {
if (!nlm_cmp_addr(nlm_addr(host), (struct sockaddr *)sin))
continue;
Expand Down

0 comments on commit c8f0805

Please sign in to comment.