aboutsummaryrefslogtreecommitdiffstats
path: root/fs/lockd/host.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/lockd/host.c')
-rw-r--r--fs/lockd/host.c49
1 files changed, 43 insertions, 6 deletions
diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index dbf3fe620a0c..1f9d72a7a030 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -22,7 +22,6 @@
22 22
23#define NLMDBG_FACILITY NLMDBG_HOSTCACHE 23#define NLMDBG_FACILITY NLMDBG_HOSTCACHE
24#define NLM_HOST_NRHASH 32 24#define NLM_HOST_NRHASH 32
25#define NLM_ADDRHASH(addr) (ntohl(addr) & (NLM_HOST_NRHASH-1))
26#define NLM_HOST_REBIND (60 * HZ) 25#define NLM_HOST_REBIND (60 * HZ)
27#define NLM_HOST_EXPIRE (300 * HZ) 26#define NLM_HOST_EXPIRE (300 * HZ)
28#define NLM_HOST_COLLECT (120 * HZ) 27#define NLM_HOST_COLLECT (120 * HZ)
@@ -40,6 +39,48 @@ static struct nsm_handle * nsm_find(const struct sockaddr_in *sin,
40 const char *hostname, 39 const char *hostname,
41 unsigned int hostname_len); 40 unsigned int hostname_len);
42 41
42/*
43 * Hash function must work well on big- and little-endian platforms
44 */
45static unsigned int __nlm_hash32(const __be32 n)
46{
47 unsigned int hash = (__force u32)n ^ ((__force u32)n >> 16);
48 return hash ^ (hash >> 8);
49}
50
51static unsigned int __nlm_hash_addr4(const struct sockaddr *sap)
52{
53 const struct sockaddr_in *sin = (struct sockaddr_in *)sap;
54 return __nlm_hash32(sin->sin_addr.s_addr);
55}
56
57static unsigned int __nlm_hash_addr6(const struct sockaddr *sap)
58{
59 const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
60 const struct in6_addr addr = sin6->sin6_addr;
61 return __nlm_hash32(addr.s6_addr32[0]) ^
62 __nlm_hash32(addr.s6_addr32[1]) ^
63 __nlm_hash32(addr.s6_addr32[2]) ^
64 __nlm_hash32(addr.s6_addr32[3]);
65}
66
67static unsigned int nlm_hash_address(const struct sockaddr *sap)
68{
69 unsigned int hash;
70
71 switch (sap->sa_family) {
72 case AF_INET:
73 hash = __nlm_hash_addr4(sap);
74 break;
75 case AF_INET6:
76 hash = __nlm_hash_addr6(sap);
77 break;
78 default:
79 hash = 0;
80 }
81 return hash & (NLM_HOST_NRHASH - 1);
82}
83
43static void nlm_clear_port(struct sockaddr *sap) 84static void nlm_clear_port(struct sockaddr *sap)
44{ 85{
45 switch (sap->sa_family) { 86 switch (sap->sa_family) {
@@ -92,16 +133,12 @@ static struct nlm_host *nlm_lookup_host(int server,
92 struct hlist_node *pos; 133 struct hlist_node *pos;
93 struct nlm_host *host; 134 struct nlm_host *host;
94 struct nsm_handle *nsm = NULL; 135 struct nsm_handle *nsm = NULL;
95 int hash;
96 136
97 dprintk("lockd: nlm_lookup_host(proto=%d, vers=%u," 137 dprintk("lockd: nlm_lookup_host(proto=%d, vers=%u,"
98 " my role is %s, hostname=%.*s)\n", 138 " my role is %s, hostname=%.*s)\n",
99 proto, version, server ? "server" : "client", 139 proto, version, server ? "server" : "client",
100 hostname_len, hostname ? hostname : "<none>"); 140 hostname_len, hostname ? hostname : "<none>");
101 141
102 hash = NLM_ADDRHASH(sin->sin_addr.s_addr);
103
104 /* Lock hash table */
105 mutex_lock(&nlm_host_mutex); 142 mutex_lock(&nlm_host_mutex);
106 143
107 if (time_after_eq(jiffies, next_gc)) 144 if (time_after_eq(jiffies, next_gc))
@@ -114,7 +151,7 @@ static struct nlm_host *nlm_lookup_host(int server,
114 * different NLM rpc_clients into one single nlm_host object. 151 * different NLM rpc_clients into one single nlm_host object.
115 * This would allow us to have one nlm_host per address. 152 * This would allow us to have one nlm_host per address.
116 */ 153 */
117 chain = &nlm_hosts[hash]; 154 chain = &nlm_hosts[nlm_hash_address((struct sockaddr *)sin)];
118 hlist_for_each_entry(host, pos, chain, h_hash) { 155 hlist_for_each_entry(host, pos, chain, h_hash) {
119 if (!nlm_cmp_addr(nlm_addr(host), (struct sockaddr *)sin)) 156 if (!nlm_cmp_addr(nlm_addr(host), (struct sockaddr *)sin))
120 continue; 157 continue;