Lines Matching full:host
3 * linux/fs/lockd/host.c
37 #define for_each_host(host, chain, table) \ argument
40 hlist_for_each_entry((host), (chain), h_hash)
42 #define for_each_host_safe(host, next, chain, table) \ argument
45 hlist_for_each_entry_safe((host), (next), \
114 struct nlm_host *host = NULL; in nlm_alloc_host() local
129 host = kmalloc(sizeof(*host), GFP_KERNEL); in nlm_alloc_host()
130 if (unlikely(host == NULL)) { in nlm_alloc_host()
136 memcpy(nlm_addr(host), ni->sap, ni->salen); in nlm_alloc_host()
137 host->h_addrlen = ni->salen; in nlm_alloc_host()
138 rpc_set_port(nlm_addr(host), 0); in nlm_alloc_host()
139 host->h_srcaddrlen = 0; in nlm_alloc_host()
141 host->h_rpcclnt = NULL; in nlm_alloc_host()
142 host->h_name = nsm->sm_name; in nlm_alloc_host()
143 host->h_version = ni->version; in nlm_alloc_host()
144 host->h_proto = ni->protocol; in nlm_alloc_host()
145 host->h_reclaiming = 0; in nlm_alloc_host()
146 host->h_server = ni->server; in nlm_alloc_host()
147 host->h_noresvport = ni->noresvport; in nlm_alloc_host()
148 host->h_inuse = 0; in nlm_alloc_host()
149 init_waitqueue_head(&host->h_gracewait); in nlm_alloc_host()
150 init_rwsem(&host->h_rwsem); in nlm_alloc_host()
151 host->h_state = 0; in nlm_alloc_host()
152 host->h_nsmstate = 0; in nlm_alloc_host()
153 host->h_pidcount = 0; in nlm_alloc_host()
154 refcount_set(&host->h_count, 1); in nlm_alloc_host()
155 mutex_init(&host->h_mutex); in nlm_alloc_host()
156 host->h_nextrebind = now + NLM_HOST_REBIND; in nlm_alloc_host()
157 host->h_expires = now + NLM_HOST_EXPIRE; in nlm_alloc_host()
158 INIT_LIST_HEAD(&host->h_lockowners); in nlm_alloc_host()
159 spin_lock_init(&host->h_lock); in nlm_alloc_host()
160 INIT_LIST_HEAD(&host->h_granted); in nlm_alloc_host()
161 INIT_LIST_HEAD(&host->h_reclaim); in nlm_alloc_host()
162 host->h_nsmhandle = nsm; in nlm_alloc_host()
163 host->h_addrbuf = nsm->sm_addrbuf; in nlm_alloc_host()
164 host->net = ni->net; in nlm_alloc_host()
165 host->h_cred = get_cred(ni->cred); in nlm_alloc_host()
166 strscpy(host->nodename, utsname()->nodename, sizeof(host->nodename)); in nlm_alloc_host()
169 return host; in nlm_alloc_host()
177 static void nlm_destroy_host_locked(struct nlm_host *host) in nlm_destroy_host_locked() argument
180 struct lockd_net *ln = net_generic(host->net, lockd_net_id); in nlm_destroy_host_locked()
182 dprintk("lockd: destroy host %s\n", host->h_name); in nlm_destroy_host_locked()
184 hlist_del_init(&host->h_hash); in nlm_destroy_host_locked()
186 nsm_unmonitor(host); in nlm_destroy_host_locked()
187 nsm_release(host->h_nsmhandle); in nlm_destroy_host_locked()
189 clnt = host->h_rpcclnt; in nlm_destroy_host_locked()
192 put_cred(host->h_cred); in nlm_destroy_host_locked()
193 kfree(host); in nlm_destroy_host_locked()
200 * nlmclnt_lookup_host - Find an NLM host handle matching a remote server
212 * If one doesn't already exist in the host cache, a new handle is
237 struct nlm_host *host; in nlmclnt_lookup_host() local
241 dprintk("lockd: %s(host='%s', vers=%u, proto=%s)\n", __func__, in nlmclnt_lookup_host()
248 hlist_for_each_entry(host, chain, h_hash) { in nlmclnt_lookup_host()
249 if (host->net != net) in nlmclnt_lookup_host()
251 if (!rpc_cmp_addr(nlm_addr(host), sap)) in nlmclnt_lookup_host()
256 nsm = host->h_nsmhandle; in nlmclnt_lookup_host()
258 if (host->h_proto != protocol) in nlmclnt_lookup_host()
260 if (host->h_version != version) in nlmclnt_lookup_host()
263 nlm_get_host(host); in nlmclnt_lookup_host()
264 dprintk("lockd: %s found host %s (%s)\n", __func__, in nlmclnt_lookup_host()
265 host->h_name, host->h_addrbuf); in nlmclnt_lookup_host()
269 host = nlm_alloc_host(&ni, nsm); in nlmclnt_lookup_host()
270 if (unlikely(host == NULL)) in nlmclnt_lookup_host()
273 hlist_add_head(&host->h_hash, chain); in nlmclnt_lookup_host()
277 dprintk("lockd: %s created host %s (%s)\n", __func__, in nlmclnt_lookup_host()
278 host->h_name, host->h_addrbuf); in nlmclnt_lookup_host()
282 return host; in nlmclnt_lookup_host()
287 * @host: nlm_host to release
290 void nlmclnt_release_host(struct nlm_host *host) in nlmclnt_release_host() argument
292 if (host == NULL) in nlmclnt_release_host()
295 dprintk("lockd: release client host %s\n", host->h_name); in nlmclnt_release_host()
297 WARN_ON_ONCE(host->h_server); in nlmclnt_release_host()
299 if (refcount_dec_and_mutex_lock(&host->h_count, &nlm_host_mutex)) { in nlmclnt_release_host()
300 WARN_ON_ONCE(!list_empty(&host->h_lockowners)); in nlmclnt_release_host()
301 WARN_ON_ONCE(!list_empty(&host->h_granted)); in nlmclnt_release_host()
302 WARN_ON_ONCE(!list_empty(&host->h_reclaim)); in nlmclnt_release_host()
304 nlm_destroy_host_locked(host); in nlmclnt_release_host()
310 * nlmsvc_lookup_host - Find an NLM host handle matching a remote client
312 * @hostname: name of client host
317 * NLM request. If one doesn't already exist in the host cache, a
332 struct nlm_host *host = NULL; in nlmsvc_lookup_host() local
349 dprintk("lockd: %s(host='%.*s', vers=%u, proto=%s)\n", __func__, in nlmsvc_lookup_host()
359 hlist_for_each_entry(host, chain, h_hash) { in nlmsvc_lookup_host()
360 if (host->net != net) in nlmsvc_lookup_host()
362 if (!rpc_cmp_addr(nlm_addr(host), ni.sap)) in nlmsvc_lookup_host()
367 nsm = host->h_nsmhandle; in nlmsvc_lookup_host()
369 if (host->h_proto != ni.protocol) in nlmsvc_lookup_host()
371 if (host->h_version != ni.version) in nlmsvc_lookup_host()
373 if (!rpc_cmp_addr(nlm_srcaddr(host), src_sap)) in nlmsvc_lookup_host()
377 hlist_del(&host->h_hash); in nlmsvc_lookup_host()
378 hlist_add_head(&host->h_hash, chain); in nlmsvc_lookup_host()
380 nlm_get_host(host); in nlmsvc_lookup_host()
381 dprintk("lockd: %s found host %s (%s)\n", in nlmsvc_lookup_host()
382 __func__, host->h_name, host->h_addrbuf); in nlmsvc_lookup_host()
386 host = nlm_alloc_host(&ni, nsm); in nlmsvc_lookup_host()
387 if (unlikely(host == NULL)) in nlmsvc_lookup_host()
390 memcpy(nlm_srcaddr(host), src_sap, src_len); in nlmsvc_lookup_host()
391 host->h_srcaddrlen = src_len; in nlmsvc_lookup_host()
392 hlist_add_head(&host->h_hash, chain); in nlmsvc_lookup_host()
396 refcount_inc(&host->h_count); in nlmsvc_lookup_host()
398 dprintk("lockd: %s created host %s (%s)\n", in nlmsvc_lookup_host()
399 __func__, host->h_name, host->h_addrbuf); in nlmsvc_lookup_host()
403 return host; in nlmsvc_lookup_host()
408 * @host: nlm_host to release
410 * Host is destroyed later in nlm_gc_host().
412 void nlmsvc_release_host(struct nlm_host *host) in nlmsvc_release_host() argument
414 if (host == NULL) in nlmsvc_release_host()
417 dprintk("lockd: release server host %s\n", host->h_name); in nlmsvc_release_host()
419 WARN_ON_ONCE(!host->h_server); in nlmsvc_release_host()
420 refcount_dec(&host->h_count); in nlmsvc_release_host()
427 nlm_bind_host(struct nlm_host *host) in nlm_bind_host() argument
432 host->h_name, host->h_addrbuf); in nlm_bind_host()
434 /* Lock host handle */ in nlm_bind_host()
435 mutex_lock(&host->h_mutex); in nlm_bind_host()
440 if ((clnt = host->h_rpcclnt) != NULL) { in nlm_bind_host()
441 nlm_rebind_host(host); in nlm_bind_host()
451 .net = host->net, in nlm_bind_host()
452 .protocol = host->h_proto, in nlm_bind_host()
453 .address = nlm_addr(host), in nlm_bind_host()
454 .addrsize = host->h_addrlen, in nlm_bind_host()
456 .servername = host->h_name, in nlm_bind_host()
458 .version = host->h_version, in nlm_bind_host()
463 .cred = host->h_cred, in nlm_bind_host()
471 if (!host->h_server) in nlm_bind_host()
473 if (host->h_noresvport) in nlm_bind_host()
475 if (host->h_srcaddrlen) in nlm_bind_host()
476 args.saddress = nlm_srcaddr(host); in nlm_bind_host()
480 host->h_rpcclnt = clnt; in nlm_bind_host()
482 printk("lockd: couldn't create RPC handle for %s\n", host->h_name); in nlm_bind_host()
487 mutex_unlock(&host->h_mutex); in nlm_bind_host()
493 * @host: NLM host handle for peer
500 nlm_rebind_host(struct nlm_host *host) in nlm_rebind_host() argument
502 if (host->h_proto != IPPROTO_UDP) in nlm_rebind_host()
505 if (host->h_rpcclnt && time_after_eq(jiffies, host->h_nextrebind)) { in nlm_rebind_host()
506 rpc_force_rebind(host->h_rpcclnt); in nlm_rebind_host()
507 host->h_nextrebind = jiffies + NLM_HOST_REBIND; in nlm_rebind_host()
512 * Increment NLM host count
514 struct nlm_host * nlm_get_host(struct nlm_host *host) in nlm_get_host() argument
516 if (host) { in nlm_get_host()
517 dprintk("lockd: get host %s\n", host->h_name); in nlm_get_host()
518 refcount_inc(&host->h_count); in nlm_get_host()
519 host->h_expires = jiffies + NLM_HOST_EXPIRE; in nlm_get_host()
521 return host; in nlm_get_host()
528 struct nlm_host *host; in next_host_state() local
532 for_each_host(host, chain, cache) { in next_host_state()
533 if (host->h_nsmhandle == nsm in next_host_state()
534 && host->h_nsmstate != info->state) { in next_host_state()
535 host->h_nsmstate = info->state; in next_host_state()
536 host->h_state++; in next_host_state()
538 nlm_get_host(host); in next_host_state()
540 return host; in next_host_state()
549 * nlm_host_rebooted - Release all resources held by rebooted host
553 * We were notified that the specified host has rebooted. Release
559 struct nlm_host *host; in nlm_host_rebooted() local
566 * We run the loop repeatedly, because we drop the host table in nlm_host_rebooted()
568 * To avoid processing a host several times, we match the nsmstate. in nlm_host_rebooted()
570 while ((host = next_host_state(nlm_server_hosts, nsm, info)) != NULL) { in nlm_host_rebooted()
571 nlmsvc_free_host_resources(host); in nlm_host_rebooted()
572 nlmsvc_release_host(host); in nlm_host_rebooted()
574 while ((host = next_host_state(nlm_client_hosts, nsm, info)) != NULL) { in nlm_host_rebooted()
575 nlmclnt_recovery(host); in nlm_host_rebooted()
576 nlmclnt_release_host(host); in nlm_host_rebooted()
585 struct nlm_host *host; in nlm_complain_hosts() local
592 pr_warn("lockd: couldn't shutdown host module for net %x!\n", in nlm_complain_hosts()
599 printk(KERN_WARNING "lockd: couldn't shutdown host module!\n"); in nlm_complain_hosts()
603 for_each_host(host, chain, nlm_server_hosts) { in nlm_complain_hosts()
604 if (net && host->net != net) in nlm_complain_hosts()
607 host->h_name, refcount_read(&host->h_count), in nlm_complain_hosts()
608 host->h_inuse, host->h_expires, host->net->ns.inum); in nlm_complain_hosts()
616 struct nlm_host *host; in nlm_shutdown_hosts_net() local
623 for_each_host(host, chain, nlm_server_hosts) { in nlm_shutdown_hosts_net()
624 if (net && host->net != net) in nlm_shutdown_hosts_net()
626 host->h_expires = jiffies - 1; in nlm_shutdown_hosts_net()
627 if (host->h_rpcclnt) { in nlm_shutdown_hosts_net()
628 rpc_shutdown_client(host->h_rpcclnt); in nlm_shutdown_hosts_net()
629 host->h_rpcclnt = NULL; in nlm_shutdown_hosts_net()
631 nlmsvc_free_host_resources(host); in nlm_shutdown_hosts_net()
647 dprintk("lockd: shutting down host module\n"); in nlm_shutdown_hosts()
661 struct nlm_host *host; in nlm_gc_hosts() local
663 dprintk("lockd: host garbage collection for net %x\n", in nlm_gc_hosts()
665 for_each_host(host, chain, nlm_server_hosts) { in nlm_gc_hosts()
666 if (net && host->net != net) in nlm_gc_hosts()
668 host->h_inuse = 0; in nlm_gc_hosts()
674 for_each_host_safe(host, next, chain, nlm_server_hosts) { in nlm_gc_hosts()
675 if (net && host->net != net) in nlm_gc_hosts()
677 if (host->h_inuse || time_before(jiffies, host->h_expires)) { in nlm_gc_hosts()
680 host->h_name, refcount_read(&host->h_count), in nlm_gc_hosts()
681 host->h_inuse, host->h_expires, in nlm_gc_hosts()
682 host->net->ns.inum); in nlm_gc_hosts()
685 if (refcount_dec_if_one(&host->h_count)) in nlm_gc_hosts()
686 nlm_destroy_host_locked(host); in nlm_gc_hosts()