Lines Matching defs:host

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