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
120 host = NULL; in nlm_alloc_host()
130 host = kmalloc(sizeof(*host), GFP_KERNEL); in nlm_alloc_host()
131 if (unlikely(host == NULL)) { in nlm_alloc_host()
137 memcpy(nlm_addr(host), ni->sap, ni->salen); in nlm_alloc_host()
138 host->h_addrlen = ni->salen; in nlm_alloc_host()
139 rpc_set_port(nlm_addr(host), 0); in nlm_alloc_host()
140 host->h_srcaddrlen = 0; in nlm_alloc_host()
142 host->h_rpcclnt = NULL; in nlm_alloc_host()
143 host->h_name = nsm->sm_name; in nlm_alloc_host()
144 host->h_version = ni->version; in nlm_alloc_host()
145 host->h_proto = ni->protocol; in nlm_alloc_host()
146 host->h_reclaiming = 0; in nlm_alloc_host()
147 host->h_server = ni->server; in nlm_alloc_host()
148 host->h_noresvport = ni->noresvport; in nlm_alloc_host()
149 host->h_inuse = 0; in nlm_alloc_host()
150 init_waitqueue_head(&host->h_gracewait); in nlm_alloc_host()
151 init_rwsem(&host->h_rwsem); in nlm_alloc_host()
152 host->h_state = 0; in nlm_alloc_host()
153 host->h_nsmstate = 0; in nlm_alloc_host()
154 host->h_pidcount = 0; in nlm_alloc_host()
155 refcount_set(&host->h_count, 1); in nlm_alloc_host()
156 mutex_init(&host->h_mutex); in nlm_alloc_host()
157 host->h_nextrebind = now + NLM_HOST_REBIND; in nlm_alloc_host()
158 host->h_expires = now + NLM_HOST_EXPIRE; in nlm_alloc_host()
159 INIT_LIST_HEAD(&host->h_lockowners); in nlm_alloc_host()
160 spin_lock_init(&host->h_lock); in nlm_alloc_host()
161 INIT_LIST_HEAD(&host->h_granted); in nlm_alloc_host()
162 INIT_LIST_HEAD(&host->h_reclaim); in nlm_alloc_host()
163 host->h_nsmhandle = nsm; in nlm_alloc_host()
164 host->h_addrbuf = nsm->sm_addrbuf; in nlm_alloc_host()
165 host->net = ni->net; in nlm_alloc_host()
166 host->h_cred = get_cred(ni->cred); in nlm_alloc_host()
167 strscpy(host->nodename, utsname()->nodename, sizeof(host->nodename)); in nlm_alloc_host()
170 return host; in nlm_alloc_host()
178 static void nlm_destroy_host_locked(struct nlm_host *host) in nlm_destroy_host_locked() argument
181 struct lockd_net *ln = net_generic(host->net, lockd_net_id); in nlm_destroy_host_locked()
183 dprintk("lockd: destroy host %s\n", host->h_name); in nlm_destroy_host_locked()
185 hlist_del_init(&host->h_hash); in nlm_destroy_host_locked()
187 nsm_unmonitor(host); in nlm_destroy_host_locked()
188 nsm_release(host->h_nsmhandle); in nlm_destroy_host_locked()
190 clnt = host->h_rpcclnt; in nlm_destroy_host_locked()
193 put_cred(host->h_cred); in nlm_destroy_host_locked()
194 kfree(host); in nlm_destroy_host_locked()
201 * nlmclnt_lookup_host - Find an NLM host handle matching a remote server
213 * If one doesn't already exist in the host cache, a new handle is
238 struct nlm_host *host; in nlmclnt_lookup_host() local
242 dprintk("lockd: %s(host='%s', vers=%u, proto=%s)\n", __func__, in nlmclnt_lookup_host()
249 hlist_for_each_entry(host, chain, h_hash) { in nlmclnt_lookup_host()
250 if (host->net != net) in nlmclnt_lookup_host()
252 if (!rpc_cmp_addr(nlm_addr(host), sap)) in nlmclnt_lookup_host()
257 nsm = host->h_nsmhandle; in nlmclnt_lookup_host()
259 if (host->h_proto != protocol) in nlmclnt_lookup_host()
261 if (host->h_version != version) in nlmclnt_lookup_host()
264 nlm_get_host(host); in nlmclnt_lookup_host()
265 dprintk("lockd: %s found host %s (%s)\n", __func__, in nlmclnt_lookup_host()
266 host->h_name, host->h_addrbuf); in nlmclnt_lookup_host()
270 host = nlm_alloc_host(&ni, nsm); in nlmclnt_lookup_host()
271 if (unlikely(host == NULL)) in nlmclnt_lookup_host()
274 hlist_add_head(&host->h_hash, chain); in nlmclnt_lookup_host()
278 dprintk("lockd: %s created host %s (%s)\n", __func__, in nlmclnt_lookup_host()
279 host->h_name, host->h_addrbuf); in nlmclnt_lookup_host()
283 return host; in nlmclnt_lookup_host()
288 * @host: nlm_host to release
291 void nlmclnt_release_host(struct nlm_host *host) in nlmclnt_release_host() argument
293 if (host == NULL) in nlmclnt_release_host()
296 dprintk("lockd: release client host %s\n", host->h_name); in nlmclnt_release_host()
298 WARN_ON_ONCE(host->h_server); in nlmclnt_release_host()
300 if (refcount_dec_and_mutex_lock(&host->h_count, &nlm_host_mutex)) { in nlmclnt_release_host()
301 WARN_ON_ONCE(!list_empty(&host->h_lockowners)); in nlmclnt_release_host()
302 WARN_ON_ONCE(!list_empty(&host->h_granted)); in nlmclnt_release_host()
303 WARN_ON_ONCE(!list_empty(&host->h_reclaim)); in nlmclnt_release_host()
305 nlm_destroy_host_locked(host); in nlmclnt_release_host()
311 * nlmsvc_lookup_host - Find an NLM host handle matching a remote client
313 * @hostname: name of client host
318 * NLM request. If one doesn't already exist in the host cache, a
333 struct nlm_host *host = NULL; in nlmsvc_lookup_host() local
350 dprintk("lockd: %s(host='%.*s', vers=%u, proto=%s)\n", __func__, in nlmsvc_lookup_host()
360 hlist_for_each_entry(host, chain, h_hash) { in nlmsvc_lookup_host()
361 if (host->net != net) in nlmsvc_lookup_host()
363 if (!rpc_cmp_addr(nlm_addr(host), ni.sap)) in nlmsvc_lookup_host()
368 nsm = host->h_nsmhandle; in nlmsvc_lookup_host()
370 if (host->h_proto != ni.protocol) in nlmsvc_lookup_host()
372 if (host->h_version != ni.version) in nlmsvc_lookup_host()
374 if (!rpc_cmp_addr(nlm_srcaddr(host), src_sap)) in nlmsvc_lookup_host()
378 hlist_del(&host->h_hash); in nlmsvc_lookup_host()
379 hlist_add_head(&host->h_hash, chain); in nlmsvc_lookup_host()
381 nlm_get_host(host); in nlmsvc_lookup_host()
382 dprintk("lockd: %s found host %s (%s)\n", in nlmsvc_lookup_host()
383 __func__, host->h_name, host->h_addrbuf); in nlmsvc_lookup_host()
387 host = nlm_alloc_host(&ni, nsm); in nlmsvc_lookup_host()
388 if (unlikely(host == NULL)) in nlmsvc_lookup_host()
391 memcpy(nlm_srcaddr(host), src_sap, src_len); in nlmsvc_lookup_host()
392 host->h_srcaddrlen = src_len; in nlmsvc_lookup_host()
393 hlist_add_head(&host->h_hash, chain); in nlmsvc_lookup_host()
397 refcount_inc(&host->h_count); in nlmsvc_lookup_host()
399 dprintk("lockd: %s created host %s (%s)\n", in nlmsvc_lookup_host()
400 __func__, host->h_name, host->h_addrbuf); in nlmsvc_lookup_host()
404 return host; in nlmsvc_lookup_host()
409 * @host: nlm_host to release
411 * Host is destroyed later in nlm_gc_host().
413 void nlmsvc_release_host(struct nlm_host *host) in nlmsvc_release_host() argument
415 if (host == NULL) in nlmsvc_release_host()
418 dprintk("lockd: release server host %s\n", host->h_name); in nlmsvc_release_host()
420 WARN_ON_ONCE(!host->h_server); in nlmsvc_release_host()
421 refcount_dec(&host->h_count); in nlmsvc_release_host()
428 nlm_bind_host(struct nlm_host *host) in nlm_bind_host() argument
433 host->h_name, host->h_addrbuf); in nlm_bind_host()
435 /* Lock host handle */ in nlm_bind_host()
436 mutex_lock(&host->h_mutex); in nlm_bind_host()
441 if ((clnt = host->h_rpcclnt) != NULL) { in nlm_bind_host()
442 nlm_rebind_host(host); in nlm_bind_host()
452 .net = host->net, in nlm_bind_host()
453 .protocol = host->h_proto, in nlm_bind_host()
454 .address = nlm_addr(host), in nlm_bind_host()
455 .addrsize = host->h_addrlen, in nlm_bind_host()
457 .servername = host->h_name, in nlm_bind_host()
459 .version = host->h_version, in nlm_bind_host()
464 .cred = host->h_cred, in nlm_bind_host()
472 if (!host->h_server) in nlm_bind_host()
474 if (host->h_noresvport) in nlm_bind_host()
476 if (host->h_srcaddrlen) in nlm_bind_host()
477 args.saddress = nlm_srcaddr(host); in nlm_bind_host()
481 host->h_rpcclnt = clnt; in nlm_bind_host()
483 printk("lockd: couldn't create RPC handle for %s\n", host->h_name); in nlm_bind_host()
488 mutex_unlock(&host->h_mutex); in nlm_bind_host()
494 * @host: NLM host handle for peer
501 nlm_rebind_host(struct nlm_host *host) in nlm_rebind_host() argument
503 if (host->h_proto != IPPROTO_UDP) in nlm_rebind_host()
506 if (host->h_rpcclnt && time_after_eq(jiffies, host->h_nextrebind)) { in nlm_rebind_host()
507 rpc_force_rebind(host->h_rpcclnt); in nlm_rebind_host()
508 host->h_nextrebind = jiffies + NLM_HOST_REBIND; in nlm_rebind_host()
513 * Increment NLM host count
515 struct nlm_host * nlm_get_host(struct nlm_host *host) in nlm_get_host() argument
517 if (host) { in nlm_get_host()
518 dprintk("lockd: get host %s\n", host->h_name); in nlm_get_host()
519 refcount_inc(&host->h_count); in nlm_get_host()
520 host->h_expires = jiffies + NLM_HOST_EXPIRE; in nlm_get_host()
522 return host; in nlm_get_host()
529 struct nlm_host *host; in next_host_state() local
533 for_each_host(host, chain, cache) { in next_host_state()
534 if (host->h_nsmhandle == nsm in next_host_state()
535 && host->h_nsmstate != info->state) { in next_host_state()
536 host->h_nsmstate = info->state; in next_host_state()
537 host->h_state++; in next_host_state()
539 nlm_get_host(host); in next_host_state()
541 return host; in next_host_state()
550 * nlm_host_rebooted - Release all resources held by rebooted host
554 * We were notified that the specified host has rebooted. Release
560 struct nlm_host *host; in nlm_host_rebooted() local
567 * We run the loop repeatedly, because we drop the host table in nlm_host_rebooted()
569 * To avoid processing a host several times, we match the nsmstate. in nlm_host_rebooted()
571 while ((host = next_host_state(nlm_server_hosts, nsm, info)) != NULL) { in nlm_host_rebooted()
572 nlmsvc_free_host_resources(host); in nlm_host_rebooted()
573 nlmsvc_release_host(host); in nlm_host_rebooted()
575 while ((host = next_host_state(nlm_client_hosts, nsm, info)) != NULL) { in nlm_host_rebooted()
576 nlmclnt_recovery(host); in nlm_host_rebooted()
577 nlmclnt_release_host(host); in nlm_host_rebooted()
586 struct nlm_host *host; in nlm_complain_hosts() local
593 pr_warn("lockd: couldn't shutdown host module for net %x!\n", in nlm_complain_hosts()
600 printk(KERN_WARNING "lockd: couldn't shutdown host module!\n"); in nlm_complain_hosts()
604 for_each_host(host, chain, nlm_server_hosts) { in nlm_complain_hosts()
605 if (net && host->net != net) in nlm_complain_hosts()
608 host->h_name, refcount_read(&host->h_count), in nlm_complain_hosts()
609 host->h_inuse, host->h_expires, host->net->ns.inum); in nlm_complain_hosts()
617 struct nlm_host *host; in nlm_shutdown_hosts_net() local
624 for_each_host(host, chain, nlm_server_hosts) { in nlm_shutdown_hosts_net()
625 if (net && host->net != net) in nlm_shutdown_hosts_net()
627 host->h_expires = jiffies - 1; in nlm_shutdown_hosts_net()
628 if (host->h_rpcclnt) { in nlm_shutdown_hosts_net()
629 rpc_shutdown_client(host->h_rpcclnt); in nlm_shutdown_hosts_net()
630 host->h_rpcclnt = NULL; 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()