Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/lockd/host.c |
| 3 | * |
| 4 | * Management for NLM peer hosts. The nlm_host struct is shared |
| 5 | * between client and server implementation. The only reason to |
| 6 | * do so is to reduce code bloat. |
| 7 | * |
| 8 | * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de> |
| 9 | */ |
| 10 | |
| 11 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/slab.h> |
| 13 | #include <linux/in.h> |
Chuck Lever | 1b333c5 | 2008-08-27 16:57:23 -0400 | [diff] [blame] | 14 | #include <linux/in6.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/sunrpc/clnt.h> |
| 16 | #include <linux/sunrpc/svc.h> |
| 17 | #include <linux/lockd/lockd.h> |
Ingo Molnar | 353ab6e | 2006-03-26 01:37:12 -0800 | [diff] [blame] | 18 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Chuck Lever | 1b333c5 | 2008-08-27 16:57:23 -0400 | [diff] [blame] | 20 | #include <net/ipv6.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | #define NLMDBG_FACILITY NLMDBG_HOSTCACHE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #define NLM_HOST_NRHASH 32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #define NLM_HOST_REBIND (60 * HZ) |
NeilBrown | 1447d25 | 2008-02-08 13:03:37 +1100 | [diff] [blame] | 25 | #define NLM_HOST_EXPIRE (300 * HZ) |
| 26 | #define NLM_HOST_COLLECT (120 * HZ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Olaf Kirch | 0cea327 | 2006-10-04 02:15:56 -0700 | [diff] [blame] | 28 | static struct hlist_head nlm_hosts[NLM_HOST_NRHASH]; |
Chuck Lever | 8ea6ecc | 2010-12-14 15:05:52 +0000 | [diff] [blame^] | 29 | static struct hlist_head nlm_client_hosts[NLM_HOST_NRHASH]; |
J. Bruce Fields | b113746 | 2010-12-14 15:05:03 +0000 | [diff] [blame] | 30 | |
| 31 | #define for_each_host(host, pos, chain, table) \ |
| 32 | for ((chain) = (table); \ |
| 33 | (chain) < (table) + NLM_HOST_NRHASH; ++(chain)) \ |
| 34 | hlist_for_each_entry((host), (pos), (chain), h_hash) |
| 35 | |
| 36 | #define for_each_host_safe(host, pos, next, chain, table) \ |
| 37 | for ((chain) = (table); \ |
| 38 | (chain) < (table) + NLM_HOST_NRHASH; ++(chain)) \ |
| 39 | hlist_for_each_entry_safe((host), (pos), (next), \ |
| 40 | (chain), h_hash) |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | static unsigned long next_gc; |
| 43 | static int nrhosts; |
Ingo Molnar | 353ab6e | 2006-03-26 01:37:12 -0800 | [diff] [blame] | 44 | static DEFINE_MUTEX(nlm_host_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | static void nlm_gc_hosts(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Chuck Lever | 7f1ed18 | 2008-10-03 12:50:07 -0400 | [diff] [blame] | 48 | struct nlm_lookup_host_info { |
| 49 | const int server; /* search for server|client */ |
Chuck Lever | 88541c8 | 2008-10-03 12:50:14 -0400 | [diff] [blame] | 50 | const struct sockaddr *sap; /* address to search for */ |
| 51 | const size_t salen; /* it's length */ |
Chuck Lever | 7f1ed18 | 2008-10-03 12:50:07 -0400 | [diff] [blame] | 52 | const unsigned short protocol; /* transport to search for*/ |
| 53 | const u32 version; /* NLM version to search for */ |
| 54 | const char *hostname; /* remote's hostname */ |
| 55 | const size_t hostname_len; /* it's length */ |
Chuck Lever | 88541c8 | 2008-10-03 12:50:14 -0400 | [diff] [blame] | 56 | const struct sockaddr *src_sap; /* our address (optional) */ |
Chuck Lever | 7f1ed18 | 2008-10-03 12:50:07 -0400 | [diff] [blame] | 57 | const size_t src_len; /* it's length */ |
Chuck Lever | 0cb2659 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 58 | const int noresvport; /* use non-priv port */ |
Chuck Lever | 7f1ed18 | 2008-10-03 12:50:07 -0400 | [diff] [blame] | 59 | }; |
| 60 | |
Chuck Lever | ede2fea | 2008-09-03 14:36:08 -0400 | [diff] [blame] | 61 | /* |
| 62 | * Hash function must work well on big- and little-endian platforms |
| 63 | */ |
| 64 | static unsigned int __nlm_hash32(const __be32 n) |
| 65 | { |
| 66 | unsigned int hash = (__force u32)n ^ ((__force u32)n >> 16); |
| 67 | return hash ^ (hash >> 8); |
| 68 | } |
| 69 | |
| 70 | static unsigned int __nlm_hash_addr4(const struct sockaddr *sap) |
| 71 | { |
| 72 | const struct sockaddr_in *sin = (struct sockaddr_in *)sap; |
| 73 | return __nlm_hash32(sin->sin_addr.s_addr); |
| 74 | } |
| 75 | |
| 76 | static unsigned int __nlm_hash_addr6(const struct sockaddr *sap) |
| 77 | { |
| 78 | const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap; |
| 79 | const struct in6_addr addr = sin6->sin6_addr; |
| 80 | return __nlm_hash32(addr.s6_addr32[0]) ^ |
| 81 | __nlm_hash32(addr.s6_addr32[1]) ^ |
| 82 | __nlm_hash32(addr.s6_addr32[2]) ^ |
| 83 | __nlm_hash32(addr.s6_addr32[3]); |
| 84 | } |
| 85 | |
| 86 | static unsigned int nlm_hash_address(const struct sockaddr *sap) |
| 87 | { |
| 88 | unsigned int hash; |
| 89 | |
| 90 | switch (sap->sa_family) { |
| 91 | case AF_INET: |
| 92 | hash = __nlm_hash_addr4(sap); |
| 93 | break; |
| 94 | case AF_INET6: |
| 95 | hash = __nlm_hash_addr6(sap); |
| 96 | break; |
| 97 | default: |
| 98 | hash = 0; |
| 99 | } |
| 100 | return hash & (NLM_HOST_NRHASH - 1); |
| 101 | } |
| 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | /* |
Chuck Lever | a7952f4 | 2010-12-14 15:05:23 +0000 | [diff] [blame] | 104 | * Allocate and initialize an nlm_host. Common to both client and server. |
| 105 | */ |
| 106 | static struct nlm_host *nlm_alloc_host(struct nlm_lookup_host_info *ni, |
| 107 | struct nsm_handle *nsm) |
| 108 | { |
| 109 | struct nlm_host *host = NULL; |
| 110 | unsigned long now = jiffies; |
| 111 | |
| 112 | if (nsm != NULL) |
| 113 | atomic_inc(&nsm->sm_count); |
| 114 | else { |
| 115 | host = NULL; |
| 116 | nsm = nsm_get_handle(ni->sap, ni->salen, |
| 117 | ni->hostname, ni->hostname_len); |
| 118 | if (unlikely(nsm == NULL)) { |
| 119 | dprintk("lockd: %s failed; no nsm handle\n", |
| 120 | __func__); |
| 121 | goto out; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | host = kmalloc(sizeof(*host), GFP_KERNEL); |
| 126 | if (unlikely(host == NULL)) { |
| 127 | dprintk("lockd: %s failed; no memory\n", __func__); |
| 128 | nsm_release(nsm); |
| 129 | goto out; |
| 130 | } |
| 131 | |
| 132 | memcpy(nlm_addr(host), ni->sap, ni->salen); |
| 133 | host->h_addrlen = ni->salen; |
| 134 | rpc_set_port(nlm_addr(host), 0); |
| 135 | host->h_srcaddrlen = 0; |
| 136 | |
| 137 | host->h_rpcclnt = NULL; |
| 138 | host->h_name = nsm->sm_name; |
| 139 | host->h_version = ni->version; |
| 140 | host->h_proto = ni->protocol; |
| 141 | host->h_reclaiming = 0; |
| 142 | host->h_server = ni->server; |
| 143 | host->h_noresvport = ni->noresvport; |
| 144 | host->h_inuse = 0; |
| 145 | init_waitqueue_head(&host->h_gracewait); |
| 146 | init_rwsem(&host->h_rwsem); |
| 147 | host->h_state = 0; |
| 148 | host->h_nsmstate = 0; |
| 149 | host->h_pidcount = 0; |
| 150 | atomic_set(&host->h_count, 1); |
| 151 | mutex_init(&host->h_mutex); |
| 152 | host->h_nextrebind = now + NLM_HOST_REBIND; |
| 153 | host->h_expires = now + NLM_HOST_EXPIRE; |
| 154 | INIT_LIST_HEAD(&host->h_lockowners); |
| 155 | spin_lock_init(&host->h_lock); |
| 156 | INIT_LIST_HEAD(&host->h_granted); |
| 157 | INIT_LIST_HEAD(&host->h_reclaim); |
| 158 | host->h_nsmhandle = nsm; |
| 159 | host->h_addrbuf = nsm->sm_addrbuf; |
| 160 | |
| 161 | out: |
| 162 | return host; |
| 163 | } |
| 164 | |
| 165 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | * Common host lookup routine for server & client |
| 167 | */ |
Chuck Lever | 7f1ed18 | 2008-10-03 12:50:07 -0400 | [diff] [blame] | 168 | static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | { |
Olaf Kirch | 0cea327 | 2006-10-04 02:15:56 -0700 | [diff] [blame] | 170 | struct hlist_head *chain; |
| 171 | struct hlist_node *pos; |
| 172 | struct nlm_host *host; |
Olaf Kirch | 8dead0d | 2006-10-04 02:15:53 -0700 | [diff] [blame] | 173 | struct nsm_handle *nsm = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Ingo Molnar | 353ab6e | 2006-03-26 01:37:12 -0800 | [diff] [blame] | 175 | mutex_lock(&nlm_host_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
| 177 | if (time_after_eq(jiffies, next_gc)) |
| 178 | nlm_gc_hosts(); |
| 179 | |
Olaf Kirch | 8dead0d | 2006-10-04 02:15:53 -0700 | [diff] [blame] | 180 | /* We may keep several nlm_host objects for a peer, because each |
| 181 | * nlm_host is identified by |
| 182 | * (address, protocol, version, server/client) |
| 183 | * We could probably simplify this a little by putting all those |
| 184 | * different NLM rpc_clients into one single nlm_host object. |
| 185 | * This would allow us to have one nlm_host per address. |
| 186 | */ |
Chuck Lever | 88541c8 | 2008-10-03 12:50:14 -0400 | [diff] [blame] | 187 | chain = &nlm_hosts[nlm_hash_address(ni->sap)]; |
Olaf Kirch | 0cea327 | 2006-10-04 02:15:56 -0700 | [diff] [blame] | 188 | hlist_for_each_entry(host, pos, chain, h_hash) { |
Jeff Layton | 4516fc0 | 2009-08-14 12:57:54 -0400 | [diff] [blame] | 189 | if (!rpc_cmp_addr(nlm_addr(host), ni->sap)) |
Olaf Kirch | 8dead0d | 2006-10-04 02:15:53 -0700 | [diff] [blame] | 190 | continue; |
| 191 | |
| 192 | /* See if we have an NSM handle for this client */ |
NeilBrown | 6b54dae | 2006-10-04 02:16:15 -0700 | [diff] [blame] | 193 | if (!nsm) |
| 194 | nsm = host->h_nsmhandle; |
Olaf Kirch | 8dead0d | 2006-10-04 02:15:53 -0700 | [diff] [blame] | 195 | |
Chuck Lever | 7f1ed18 | 2008-10-03 12:50:07 -0400 | [diff] [blame] | 196 | if (host->h_proto != ni->protocol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | continue; |
Chuck Lever | 7f1ed18 | 2008-10-03 12:50:07 -0400 | [diff] [blame] | 198 | if (host->h_version != ni->version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | continue; |
Chuck Lever | 7f1ed18 | 2008-10-03 12:50:07 -0400 | [diff] [blame] | 200 | if (host->h_server != ni->server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | continue; |
Trond Myklebust | 8e35f8e | 2010-11-02 09:11:55 -0400 | [diff] [blame] | 202 | if (ni->server && ni->src_len != 0 && |
Jeff Layton | 4516fc0 | 2009-08-14 12:57:54 -0400 | [diff] [blame] | 203 | !rpc_cmp_addr(nlm_srcaddr(host), ni->src_sap)) |
Frank van Maarseveen | c98451b | 2007-07-09 22:25:29 +0200 | [diff] [blame] | 204 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Olaf Kirch | 0cea327 | 2006-10-04 02:15:56 -0700 | [diff] [blame] | 206 | /* Move to head of hash chain. */ |
| 207 | hlist_del(&host->h_hash); |
| 208 | hlist_add_head(&host->h_hash, chain); |
| 209 | |
Olaf Kirch | f0737a3 | 2006-10-04 02:15:54 -0700 | [diff] [blame] | 210 | nlm_get_host(host); |
Chuck Lever | 1b333c5 | 2008-08-27 16:57:23 -0400 | [diff] [blame] | 211 | dprintk("lockd: nlm_lookup_host found host %s (%s)\n", |
| 212 | host->h_name, host->h_addrbuf); |
Olaf Kirch | f0737a3 | 2006-10-04 02:15:54 -0700 | [diff] [blame] | 213 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |
Chuck Lever | c2526f4 | 2008-08-27 16:57:15 -0400 | [diff] [blame] | 215 | |
Chuck Lever | a7952f4 | 2010-12-14 15:05:23 +0000 | [diff] [blame] | 216 | host = nlm_alloc_host(ni, nsm); |
| 217 | if (unlikely(host == NULL)) |
Olaf Kirch | 8dead0d | 2006-10-04 02:15:53 -0700 | [diff] [blame] | 218 | goto out; |
Chuck Lever | a7952f4 | 2010-12-14 15:05:23 +0000 | [diff] [blame] | 219 | |
Chuck Lever | 88541c8 | 2008-10-03 12:50:14 -0400 | [diff] [blame] | 220 | memcpy(nlm_srcaddr(host), ni->src_sap, ni->src_len); |
Trond Myklebust | 8e35f8e | 2010-11-02 09:11:55 -0400 | [diff] [blame] | 221 | host->h_srcaddrlen = ni->src_len; |
Olaf Kirch | 0cea327 | 2006-10-04 02:15:56 -0700 | [diff] [blame] | 222 | hlist_add_head(&host->h_hash, chain); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
NeilBrown | 1447d25 | 2008-02-08 13:03:37 +1100 | [diff] [blame] | 224 | nrhosts++; |
Chuck Lever | 1b333c5 | 2008-08-27 16:57:23 -0400 | [diff] [blame] | 225 | |
Chuck Lever | 1b333c5 | 2008-08-27 16:57:23 -0400 | [diff] [blame] | 226 | dprintk("lockd: nlm_lookup_host created host %s\n", |
| 227 | host->h_name); |
| 228 | |
Olaf Kirch | 8dead0d | 2006-10-04 02:15:53 -0700 | [diff] [blame] | 229 | out: |
Ingo Molnar | 353ab6e | 2006-03-26 01:37:12 -0800 | [diff] [blame] | 230 | mutex_unlock(&nlm_host_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | return host; |
| 232 | } |
| 233 | |
Olaf Kirch | c53c1bb | 2006-10-04 02:16:00 -0700 | [diff] [blame] | 234 | /* |
Chuck Lever | 723bb5b | 2010-12-14 15:05:33 +0000 | [diff] [blame] | 235 | * Destroy an nlm_host and free associated resources |
| 236 | * |
| 237 | * Caller must hold nlm_host_mutex. |
Olaf Kirch | c53c1bb | 2006-10-04 02:16:00 -0700 | [diff] [blame] | 238 | */ |
Chuck Lever | 723bb5b | 2010-12-14 15:05:33 +0000 | [diff] [blame] | 239 | static void nlm_destroy_host_locked(struct nlm_host *host) |
Olaf Kirch | c53c1bb | 2006-10-04 02:16:00 -0700 | [diff] [blame] | 240 | { |
| 241 | struct rpc_clnt *clnt; |
| 242 | |
Chuck Lever | 723bb5b | 2010-12-14 15:05:33 +0000 | [diff] [blame] | 243 | dprintk("lockd: destroy host %s\n", host->h_name); |
| 244 | |
Olaf Kirch | c53c1bb | 2006-10-04 02:16:00 -0700 | [diff] [blame] | 245 | BUG_ON(!list_empty(&host->h_lockowners)); |
| 246 | BUG_ON(atomic_read(&host->h_count)); |
| 247 | |
Chuck Lever | 723bb5b | 2010-12-14 15:05:33 +0000 | [diff] [blame] | 248 | hlist_del_init(&host->h_hash); |
| 249 | |
Olaf Kirch | c53c1bb | 2006-10-04 02:16:00 -0700 | [diff] [blame] | 250 | nsm_unmonitor(host); |
Chuck Lever | c8c23c4 | 2008-12-04 14:21:31 -0500 | [diff] [blame] | 251 | nsm_release(host->h_nsmhandle); |
Olaf Kirch | c53c1bb | 2006-10-04 02:16:00 -0700 | [diff] [blame] | 252 | |
Trond Myklebust | 34f52e3 | 2007-06-14 16:40:31 -0400 | [diff] [blame] | 253 | clnt = host->h_rpcclnt; |
| 254 | if (clnt != NULL) |
| 255 | rpc_shutdown_client(clnt); |
Olaf Kirch | c53c1bb | 2006-10-04 02:16:00 -0700 | [diff] [blame] | 256 | kfree(host); |
Chuck Lever | 723bb5b | 2010-12-14 15:05:33 +0000 | [diff] [blame] | 257 | |
| 258 | nrhosts--; |
Olaf Kirch | c53c1bb | 2006-10-04 02:16:00 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Chuck Lever | d7d2044 | 2008-10-03 12:50:21 -0400 | [diff] [blame] | 261 | /** |
| 262 | * nlmclnt_lookup_host - Find an NLM host handle matching a remote server |
| 263 | * @sap: network address of server |
| 264 | * @salen: length of server address |
| 265 | * @protocol: transport protocol to use |
| 266 | * @version: NLM protocol version |
| 267 | * @hostname: '\0'-terminated hostname of server |
Chuck Lever | 0cb2659 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 268 | * @noresvport: 1 if non-privileged port should be used |
Chuck Lever | d7d2044 | 2008-10-03 12:50:21 -0400 | [diff] [blame] | 269 | * |
| 270 | * Returns an nlm_host structure that matches the passed-in |
| 271 | * [server address, transport protocol, NLM version, server hostname]. |
| 272 | * If one doesn't already exist in the host cache, a new handle is |
| 273 | * created and returned. |
Adrian Bunk | c585646 | 2006-12-06 20:38:29 -0800 | [diff] [blame] | 274 | */ |
Chuck Lever | d7d2044 | 2008-10-03 12:50:21 -0400 | [diff] [blame] | 275 | struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap, |
| 276 | const size_t salen, |
| 277 | const unsigned short protocol, |
Chuck Lever | 0cb2659 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 278 | const u32 version, |
| 279 | const char *hostname, |
| 280 | int noresvport) |
Adrian Bunk | c585646 | 2006-12-06 20:38:29 -0800 | [diff] [blame] | 281 | { |
Chuck Lever | 7f1ed18 | 2008-10-03 12:50:07 -0400 | [diff] [blame] | 282 | struct nlm_lookup_host_info ni = { |
| 283 | .server = 0, |
Chuck Lever | d7d2044 | 2008-10-03 12:50:21 -0400 | [diff] [blame] | 284 | .sap = sap, |
| 285 | .salen = salen, |
| 286 | .protocol = protocol, |
Chuck Lever | 7f1ed18 | 2008-10-03 12:50:07 -0400 | [diff] [blame] | 287 | .version = version, |
| 288 | .hostname = hostname, |
Chuck Lever | d7d2044 | 2008-10-03 12:50:21 -0400 | [diff] [blame] | 289 | .hostname_len = strlen(hostname), |
Chuck Lever | 0cb2659 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 290 | .noresvport = noresvport, |
Chuck Lever | 7f1ed18 | 2008-10-03 12:50:07 -0400 | [diff] [blame] | 291 | }; |
Chuck Lever | 8ea6ecc | 2010-12-14 15:05:52 +0000 | [diff] [blame^] | 292 | struct hlist_head *chain; |
| 293 | struct hlist_node *pos; |
| 294 | struct nlm_host *host; |
| 295 | struct nsm_handle *nsm = NULL; |
Frank van Maarseveen | c98451b | 2007-07-09 22:25:29 +0200 | [diff] [blame] | 296 | |
Chuck Lever | 7f1ed18 | 2008-10-03 12:50:07 -0400 | [diff] [blame] | 297 | dprintk("lockd: %s(host='%s', vers=%u, proto=%s)\n", __func__, |
| 298 | (hostname ? hostname : "<none>"), version, |
Chuck Lever | d7d2044 | 2008-10-03 12:50:21 -0400 | [diff] [blame] | 299 | (protocol == IPPROTO_UDP ? "udp" : "tcp")); |
Chuck Lever | 7f1ed18 | 2008-10-03 12:50:07 -0400 | [diff] [blame] | 300 | |
Chuck Lever | 8ea6ecc | 2010-12-14 15:05:52 +0000 | [diff] [blame^] | 301 | mutex_lock(&nlm_host_mutex); |
| 302 | |
| 303 | chain = &nlm_client_hosts[nlm_hash_address(sap)]; |
| 304 | hlist_for_each_entry(host, pos, chain, h_hash) { |
| 305 | if (!rpc_cmp_addr(nlm_addr(host), sap)) |
| 306 | continue; |
| 307 | |
| 308 | /* Same address. Share an NSM handle if we already have one */ |
| 309 | if (nsm == NULL) |
| 310 | nsm = host->h_nsmhandle; |
| 311 | |
| 312 | if (host->h_proto != protocol) |
| 313 | continue; |
| 314 | if (host->h_version != version) |
| 315 | continue; |
| 316 | |
| 317 | nlm_get_host(host); |
| 318 | dprintk("lockd: %s found host %s (%s)\n", __func__, |
| 319 | host->h_name, host->h_addrbuf); |
| 320 | goto out; |
| 321 | } |
| 322 | |
| 323 | host = nlm_alloc_host(&ni, nsm); |
| 324 | if (unlikely(host == NULL)) |
| 325 | goto out; |
| 326 | |
| 327 | hlist_add_head(&host->h_hash, chain); |
| 328 | nrhosts++; |
| 329 | |
| 330 | dprintk("lockd: %s created host %s (%s)\n", __func__, |
| 331 | host->h_name, host->h_addrbuf); |
| 332 | |
| 333 | out: |
| 334 | mutex_unlock(&nlm_host_mutex); |
| 335 | return host; |
| 336 | } |
| 337 | |
| 338 | /** |
| 339 | * nlmclnt_release_host - release client nlm_host |
| 340 | * @host: nlm_host to release |
| 341 | * |
| 342 | */ |
| 343 | void nlmclnt_release_host(struct nlm_host *host) |
| 344 | { |
| 345 | if (host == NULL) |
| 346 | return; |
| 347 | |
| 348 | dprintk("lockd: release client host %s\n", host->h_name); |
| 349 | |
| 350 | BUG_ON(atomic_read(&host->h_count) < 0); |
| 351 | BUG_ON(host->h_server); |
| 352 | |
| 353 | if (atomic_dec_and_test(&host->h_count)) { |
| 354 | BUG_ON(!list_empty(&host->h_lockowners)); |
| 355 | BUG_ON(!list_empty(&host->h_granted)); |
| 356 | BUG_ON(!list_empty(&host->h_reclaim)); |
| 357 | |
| 358 | mutex_lock(&nlm_host_mutex); |
| 359 | nlm_destroy_host_locked(host); |
| 360 | mutex_unlock(&nlm_host_mutex); |
| 361 | } |
Adrian Bunk | c585646 | 2006-12-06 20:38:29 -0800 | [diff] [blame] | 362 | } |
| 363 | |
Chuck Lever | 6bfbe8a | 2008-10-03 12:50:29 -0400 | [diff] [blame] | 364 | /** |
| 365 | * nlmsvc_lookup_host - Find an NLM host handle matching a remote client |
| 366 | * @rqstp: incoming NLM request |
| 367 | * @hostname: name of client host |
| 368 | * @hostname_len: length of client hostname |
| 369 | * |
| 370 | * Returns an nlm_host structure that matches the [client address, |
| 371 | * transport protocol, NLM version, client hostname] of the passed-in |
| 372 | * NLM request. If one doesn't already exist in the host cache, a |
| 373 | * new handle is created and returned. |
| 374 | * |
| 375 | * Before possibly creating a new nlm_host, construct a sockaddr |
| 376 | * for a specific source address in case the local system has |
| 377 | * multiple network addresses. The family of the address in |
| 378 | * rq_daddr is guaranteed to be the same as the family of the |
| 379 | * address in rq_addr, so it's safe to use the same family for |
| 380 | * the source address. |
Adrian Bunk | c585646 | 2006-12-06 20:38:29 -0800 | [diff] [blame] | 381 | */ |
Chuck Lever | 6bfbe8a | 2008-10-03 12:50:29 -0400 | [diff] [blame] | 382 | struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp, |
| 383 | const char *hostname, |
| 384 | const size_t hostname_len) |
Adrian Bunk | c585646 | 2006-12-06 20:38:29 -0800 | [diff] [blame] | 385 | { |
Chuck Lever | 6bfbe8a | 2008-10-03 12:50:29 -0400 | [diff] [blame] | 386 | struct sockaddr_in sin = { |
Chuck Lever | 2860a02 | 2008-08-27 16:57:31 -0400 | [diff] [blame] | 387 | .sin_family = AF_INET, |
Chuck Lever | 6bfbe8a | 2008-10-03 12:50:29 -0400 | [diff] [blame] | 388 | }; |
| 389 | struct sockaddr_in6 sin6 = { |
| 390 | .sin6_family = AF_INET6, |
Chuck Lever | 2860a02 | 2008-08-27 16:57:31 -0400 | [diff] [blame] | 391 | }; |
Chuck Lever | 7f1ed18 | 2008-10-03 12:50:07 -0400 | [diff] [blame] | 392 | struct nlm_lookup_host_info ni = { |
| 393 | .server = 1, |
Chuck Lever | 88541c8 | 2008-10-03 12:50:14 -0400 | [diff] [blame] | 394 | .sap = svc_addr(rqstp), |
| 395 | .salen = rqstp->rq_addrlen, |
Chuck Lever | 7f1ed18 | 2008-10-03 12:50:07 -0400 | [diff] [blame] | 396 | .protocol = rqstp->rq_prot, |
| 397 | .version = rqstp->rq_vers, |
| 398 | .hostname = hostname, |
| 399 | .hostname_len = hostname_len, |
Chuck Lever | 6bfbe8a | 2008-10-03 12:50:29 -0400 | [diff] [blame] | 400 | .src_len = rqstp->rq_addrlen, |
Chuck Lever | 7f1ed18 | 2008-10-03 12:50:07 -0400 | [diff] [blame] | 401 | }; |
Frank van Maarseveen | c98451b | 2007-07-09 22:25:29 +0200 | [diff] [blame] | 402 | |
Chuck Lever | 7f1ed18 | 2008-10-03 12:50:07 -0400 | [diff] [blame] | 403 | dprintk("lockd: %s(host='%*s', vers=%u, proto=%s)\n", __func__, |
| 404 | (int)hostname_len, hostname, rqstp->rq_vers, |
| 405 | (rqstp->rq_prot == IPPROTO_UDP ? "udp" : "tcp")); |
| 406 | |
Chuck Lever | 6bfbe8a | 2008-10-03 12:50:29 -0400 | [diff] [blame] | 407 | switch (ni.sap->sa_family) { |
| 408 | case AF_INET: |
| 409 | sin.sin_addr.s_addr = rqstp->rq_daddr.addr.s_addr; |
| 410 | ni.src_sap = (struct sockaddr *)&sin; |
| 411 | break; |
| 412 | case AF_INET6: |
| 413 | ipv6_addr_copy(&sin6.sin6_addr, &rqstp->rq_daddr.addr6); |
| 414 | ni.src_sap = (struct sockaddr *)&sin6; |
| 415 | break; |
| 416 | default: |
| 417 | return NULL; |
| 418 | } |
| 419 | |
Chuck Lever | 7f1ed18 | 2008-10-03 12:50:07 -0400 | [diff] [blame] | 420 | return nlm_lookup_host(&ni); |
Adrian Bunk | c585646 | 2006-12-06 20:38:29 -0800 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | * Create the NLM RPC client for an NLM peer |
| 425 | */ |
| 426 | struct rpc_clnt * |
| 427 | nlm_bind_host(struct nlm_host *host) |
| 428 | { |
| 429 | struct rpc_clnt *clnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
Chuck Lever | 1df40b6 | 2008-12-04 14:19:53 -0500 | [diff] [blame] | 431 | dprintk("lockd: nlm_bind_host %s (%s)\n", |
| 432 | host->h_name, host->h_addrbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
| 434 | /* Lock host handle */ |
Trond Myklebust | 5046791 | 2006-06-09 09:40:24 -0400 | [diff] [blame] | 435 | mutex_lock(&host->h_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
| 437 | /* If we've already created an RPC client, check whether |
| 438 | * RPC rebind is required |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | */ |
| 440 | if ((clnt = host->h_rpcclnt) != NULL) { |
Chuck Lever | 43118c2 | 2005-08-25 16:25:49 -0700 | [diff] [blame] | 441 | if (time_after_eq(jiffies, host->h_nextrebind)) { |
Chuck Lever | 35f5a42 | 2006-01-03 09:55:50 +0100 | [diff] [blame] | 442 | rpc_force_rebind(clnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | host->h_nextrebind = jiffies + NLM_HOST_REBIND; |
Chuck Lever | 1b333c5 | 2008-08-27 16:57:23 -0400 | [diff] [blame] | 444 | dprintk("lockd: next rebind in %lu jiffies\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | host->h_nextrebind - jiffies); |
| 446 | } |
| 447 | } else { |
Trond Myklebust | 21051ba | 2007-05-14 16:50:44 -0400 | [diff] [blame] | 448 | unsigned long increment = nlmsvc_timeout; |
Chuck Lever | e1ec789 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 449 | struct rpc_timeout timeparms = { |
| 450 | .to_initval = increment, |
| 451 | .to_increment = increment, |
| 452 | .to_maxval = increment * 6UL, |
| 453 | .to_retries = 5U, |
| 454 | }; |
| 455 | struct rpc_create_args args = { |
Pavel Emelyanov | c653ce3 | 2010-09-29 16:04:45 +0400 | [diff] [blame] | 456 | .net = &init_net, |
Chuck Lever | e1ec789 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 457 | .protocol = host->h_proto, |
Chuck Lever | b4ed58f | 2008-09-03 14:35:39 -0400 | [diff] [blame] | 458 | .address = nlm_addr(host), |
| 459 | .addrsize = host->h_addrlen, |
Chuck Lever | e1ec789 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 460 | .timeout = &timeparms, |
| 461 | .servername = host->h_name, |
| 462 | .program = &nlm_program, |
| 463 | .version = host->h_version, |
| 464 | .authflavor = RPC_AUTH_UNIX, |
Jeff Layton | 90bd17c | 2008-02-06 11:34:11 -0500 | [diff] [blame] | 465 | .flags = (RPC_CLNT_CREATE_NOPING | |
Chuck Lever | e1ec789 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 466 | RPC_CLNT_CREATE_AUTOBIND), |
| 467 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | |
Jeff Layton | 90bd17c | 2008-02-06 11:34:11 -0500 | [diff] [blame] | 469 | /* |
| 470 | * lockd retries server side blocks automatically so we want |
| 471 | * those to be soft RPC calls. Client side calls need to be |
| 472 | * hard RPC tasks. |
| 473 | */ |
| 474 | if (!host->h_server) |
| 475 | args.flags |= RPC_CLNT_CREATE_HARDRTRY; |
Chuck Lever | 0cb2659 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 476 | if (host->h_noresvport) |
| 477 | args.flags |= RPC_CLNT_CREATE_NONPRIVPORT; |
Trond Myklebust | 8e35f8e | 2010-11-02 09:11:55 -0400 | [diff] [blame] | 478 | if (host->h_srcaddrlen) |
| 479 | args.saddress = nlm_srcaddr(host); |
Jeff Layton | 90bd17c | 2008-02-06 11:34:11 -0500 | [diff] [blame] | 480 | |
Chuck Lever | e1ec789 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 481 | clnt = rpc_create(&args); |
| 482 | if (!IS_ERR(clnt)) |
| 483 | host->h_rpcclnt = clnt; |
| 484 | else { |
| 485 | printk("lockd: couldn't create RPC handle for %s\n", host->h_name); |
| 486 | clnt = NULL; |
| 487 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Trond Myklebust | 5046791 | 2006-06-09 09:40:24 -0400 | [diff] [blame] | 490 | mutex_unlock(&host->h_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | return clnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | /* |
| 495 | * Force a portmap lookup of the remote lockd port |
| 496 | */ |
| 497 | void |
| 498 | nlm_rebind_host(struct nlm_host *host) |
| 499 | { |
| 500 | dprintk("lockd: rebind host %s\n", host->h_name); |
| 501 | if (host->h_rpcclnt && time_after_eq(jiffies, host->h_nextrebind)) { |
Chuck Lever | 35f5a42 | 2006-01-03 09:55:50 +0100 | [diff] [blame] | 502 | rpc_force_rebind(host->h_rpcclnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | host->h_nextrebind = jiffies + NLM_HOST_REBIND; |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | /* |
| 508 | * Increment NLM host count |
| 509 | */ |
| 510 | struct nlm_host * nlm_get_host(struct nlm_host *host) |
| 511 | { |
| 512 | if (host) { |
| 513 | dprintk("lockd: get host %s\n", host->h_name); |
| 514 | atomic_inc(&host->h_count); |
| 515 | host->h_expires = jiffies + NLM_HOST_EXPIRE; |
| 516 | } |
| 517 | return host; |
| 518 | } |
| 519 | |
| 520 | /* |
| 521 | * Release NLM host after use |
| 522 | */ |
| 523 | void nlm_release_host(struct nlm_host *host) |
| 524 | { |
| 525 | if (host != NULL) { |
| 526 | dprintk("lockd: release host %s\n", host->h_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | BUG_ON(atomic_read(&host->h_count) < 0); |
Trond Myklebust | 4c060b5 | 2006-03-20 13:44:41 -0500 | [diff] [blame] | 528 | if (atomic_dec_and_test(&host->h_count)) { |
| 529 | BUG_ON(!list_empty(&host->h_lockowners)); |
| 530 | BUG_ON(!list_empty(&host->h_granted)); |
| 531 | BUG_ON(!list_empty(&host->h_reclaim)); |
| 532 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | |
J. Bruce Fields | b10e30f | 2010-12-14 15:05:13 +0000 | [diff] [blame] | 536 | static struct nlm_host *next_host_state(struct hlist_head *cache, |
| 537 | struct nsm_handle *nsm, |
| 538 | const struct nlm_reboot *info) |
| 539 | { |
| 540 | struct nlm_host *host = NULL; |
| 541 | struct hlist_head *chain; |
| 542 | struct hlist_node *pos; |
| 543 | |
| 544 | mutex_lock(&nlm_host_mutex); |
| 545 | for_each_host(host, pos, chain, cache) { |
| 546 | if (host->h_nsmhandle == nsm |
| 547 | && host->h_nsmstate != info->state) { |
| 548 | host->h_nsmstate = info->state; |
| 549 | host->h_state++; |
| 550 | |
| 551 | nlm_get_host(host); |
| 552 | mutex_unlock(&nlm_host_mutex); |
| 553 | goto out; |
| 554 | } |
| 555 | } |
| 556 | out: |
| 557 | mutex_unlock(&nlm_host_mutex); |
| 558 | return host; |
| 559 | } |
| 560 | |
Chuck Lever | 7fefc9c | 2008-12-05 19:03:31 -0500 | [diff] [blame] | 561 | /** |
| 562 | * nlm_host_rebooted - Release all resources held by rebooted host |
| 563 | * @info: pointer to decoded results of NLM_SM_NOTIFY call |
| 564 | * |
| 565 | * We were notified that the specified host has rebooted. Release |
| 566 | * all resources held by that peer. |
Olaf Kirch | cf712c2 | 2006-10-04 02:15:52 -0700 | [diff] [blame] | 567 | */ |
Chuck Lever | 7fefc9c | 2008-12-05 19:03:31 -0500 | [diff] [blame] | 568 | void nlm_host_rebooted(const struct nlm_reboot *info) |
Olaf Kirch | cf712c2 | 2006-10-04 02:15:52 -0700 | [diff] [blame] | 569 | { |
Olaf Kirch | 5c8dd29 | 2006-10-04 02:15:55 -0700 | [diff] [blame] | 570 | struct nsm_handle *nsm; |
Olaf Kirch | 0cea327 | 2006-10-04 02:15:56 -0700 | [diff] [blame] | 571 | struct nlm_host *host; |
Olaf Kirch | cf712c2 | 2006-10-04 02:15:52 -0700 | [diff] [blame] | 572 | |
Chuck Lever | 8c7378f | 2008-12-05 19:03:54 -0500 | [diff] [blame] | 573 | nsm = nsm_reboot_lookup(info); |
| 574 | if (unlikely(nsm == NULL)) |
Olaf Kirch | db4e4c9 | 2006-10-04 02:15:52 -0700 | [diff] [blame] | 575 | return; |
Olaf Kirch | 5c8dd29 | 2006-10-04 02:15:55 -0700 | [diff] [blame] | 576 | |
| 577 | /* Mark all hosts tied to this NSM state as having rebooted. |
| 578 | * We run the loop repeatedly, because we drop the host table |
| 579 | * lock for this. |
| 580 | * To avoid processing a host several times, we match the nsmstate. |
| 581 | */ |
J. Bruce Fields | b10e30f | 2010-12-14 15:05:13 +0000 | [diff] [blame] | 582 | while ((host = next_host_state(nlm_hosts, nsm, info)) != NULL) { |
Chuck Lever | 8ea6ecc | 2010-12-14 15:05:52 +0000 | [diff] [blame^] | 583 | nlmsvc_free_host_resources(host); |
J. Bruce Fields | b10e30f | 2010-12-14 15:05:13 +0000 | [diff] [blame] | 584 | nlm_release_host(host); |
Olaf Kirch | cf712c2 | 2006-10-04 02:15:52 -0700 | [diff] [blame] | 585 | } |
Chuck Lever | 8ea6ecc | 2010-12-14 15:05:52 +0000 | [diff] [blame^] | 586 | while ((host = next_host_state(nlm_client_hosts, nsm, info)) != NULL) { |
| 587 | nlmclnt_recovery(host); |
| 588 | nlmclnt_release_host(host); |
| 589 | } |
| 590 | |
Jeff Layton | cdd30fa | 2010-02-05 15:09:12 -0500 | [diff] [blame] | 591 | nsm_release(nsm); |
Olaf Kirch | cf712c2 | 2006-10-04 02:15:52 -0700 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | * Shut down the hosts module. |
| 596 | * Note that this routine is called only at server shutdown time. |
| 597 | */ |
| 598 | void |
| 599 | nlm_shutdown_hosts(void) |
| 600 | { |
Olaf Kirch | 0cea327 | 2006-10-04 02:15:56 -0700 | [diff] [blame] | 601 | struct hlist_head *chain; |
| 602 | struct hlist_node *pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | struct nlm_host *host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | |
| 605 | dprintk("lockd: shutting down host module\n"); |
Ingo Molnar | 353ab6e | 2006-03-26 01:37:12 -0800 | [diff] [blame] | 606 | mutex_lock(&nlm_host_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
| 608 | /* First, make all hosts eligible for gc */ |
| 609 | dprintk("lockd: nuking all hosts...\n"); |
J. Bruce Fields | b113746 | 2010-12-14 15:05:03 +0000 | [diff] [blame] | 610 | for_each_host(host, pos, chain, nlm_hosts) { |
| 611 | host->h_expires = jiffies - 1; |
| 612 | if (host->h_rpcclnt) { |
| 613 | rpc_shutdown_client(host->h_rpcclnt); |
| 614 | host->h_rpcclnt = NULL; |
Jeff Layton | d801b86 | 2008-01-29 10:30:55 -0500 | [diff] [blame] | 615 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | /* Then, perform a garbage collection pass */ |
| 619 | nlm_gc_hosts(); |
Ingo Molnar | 353ab6e | 2006-03-26 01:37:12 -0800 | [diff] [blame] | 620 | mutex_unlock(&nlm_host_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
| 622 | /* complain if any hosts are left */ |
| 623 | if (nrhosts) { |
| 624 | printk(KERN_WARNING "lockd: couldn't shutdown host module!\n"); |
| 625 | dprintk("lockd: %d hosts left:\n", nrhosts); |
J. Bruce Fields | b113746 | 2010-12-14 15:05:03 +0000 | [diff] [blame] | 626 | for_each_host(host, pos, chain, nlm_hosts) { |
| 627 | dprintk(" %s (cnt %d use %d exp %ld)\n", |
| 628 | host->h_name, atomic_read(&host->h_count), |
| 629 | host->h_inuse, host->h_expires); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | } |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | /* |
| 635 | * Garbage collect any unused NLM hosts. |
| 636 | * This GC combines reference counting for async operations with |
| 637 | * mark & sweep for resources held by remote clients. |
| 638 | */ |
| 639 | static void |
| 640 | nlm_gc_hosts(void) |
| 641 | { |
Olaf Kirch | 0cea327 | 2006-10-04 02:15:56 -0700 | [diff] [blame] | 642 | struct hlist_head *chain; |
| 643 | struct hlist_node *pos, *next; |
| 644 | struct nlm_host *host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | |
| 646 | dprintk("lockd: host garbage collection\n"); |
J. Bruce Fields | b113746 | 2010-12-14 15:05:03 +0000 | [diff] [blame] | 647 | for_each_host(host, pos, chain, nlm_hosts) |
| 648 | host->h_inuse = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | |
| 650 | /* Mark all hosts that hold locks, blocks or shares */ |
| 651 | nlmsvc_mark_resources(); |
| 652 | |
J. Bruce Fields | b113746 | 2010-12-14 15:05:03 +0000 | [diff] [blame] | 653 | for_each_host_safe(host, pos, next, chain, nlm_hosts) { |
| 654 | if (atomic_read(&host->h_count) || host->h_inuse |
| 655 | || time_before(jiffies, host->h_expires)) { |
| 656 | dprintk("nlm_gc_hosts skipping %s " |
| 657 | "(cnt %d use %d exp %ld)\n", |
| 658 | host->h_name, atomic_read(&host->h_count), |
| 659 | host->h_inuse, host->h_expires); |
| 660 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | } |
Chuck Lever | 723bb5b | 2010-12-14 15:05:33 +0000 | [diff] [blame] | 662 | nlm_destroy_host_locked(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | next_gc = jiffies + NLM_HOST_COLLECT; |
| 666 | } |