aboutsummaryrefslogtreecommitdiffstats
path: root/fs/lockd
diff options
context:
space:
mode:
authorJ. Bruce Fields <bfields@citi.umich.edu>2010-12-14 10:05:03 -0500
committerTrond Myklebust <Trond.Myklebust@netapp.com>2010-12-16 12:37:26 -0500
commitb113746888c260a02f6ae1e92b0b9ef7e9c38993 (patch)
treead9e89b3e5bae544d3a9b04bc8feb02d2ee4b17c /fs/lockd
parentbf2695516db982e90a22fc94f93491b481796bb1 (diff)
lockd: define host_for_each{_safe} macros
We've got a lot of loops like this, and I find them a little easier to read with the macros. More such loops are coming. Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu> [ cel: Forward-ported to 2.6.37 ] Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/lockd')
-rw-r--r--fs/lockd/host.c107
1 files changed, 55 insertions, 52 deletions
diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index ed0c59fe23c..cada3a12d55 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -26,6 +26,18 @@
26#define NLM_HOST_COLLECT (120 * HZ) 26#define NLM_HOST_COLLECT (120 * HZ)
27 27
28static struct hlist_head nlm_hosts[NLM_HOST_NRHASH]; 28static struct hlist_head nlm_hosts[NLM_HOST_NRHASH];
29
30#define for_each_host(host, pos, chain, table) \
31 for ((chain) = (table); \
32 (chain) < (table) + NLM_HOST_NRHASH; ++(chain)) \
33 hlist_for_each_entry((host), (pos), (chain), h_hash)
34
35#define for_each_host_safe(host, pos, next, chain, table) \
36 for ((chain) = (table); \
37 (chain) < (table) + NLM_HOST_NRHASH; ++(chain)) \
38 hlist_for_each_entry_safe((host), (pos), (next), \
39 (chain), h_hash)
40
29static unsigned long next_gc; 41static unsigned long next_gc;
30static int nrhosts; 42static int nrhosts;
31static DEFINE_MUTEX(nlm_host_mutex); 43static DEFINE_MUTEX(nlm_host_mutex);
@@ -453,28 +465,26 @@ void nlm_host_rebooted(const struct nlm_reboot *info)
453 * To avoid processing a host several times, we match the nsmstate. 465 * To avoid processing a host several times, we match the nsmstate.
454 */ 466 */
455again: mutex_lock(&nlm_host_mutex); 467again: mutex_lock(&nlm_host_mutex);
456 for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) { 468 for_each_host(host, pos, chain, nlm_hosts) {
457 hlist_for_each_entry(host, pos, chain, h_hash) { 469 if (host->h_nsmhandle == nsm
458 if (host->h_nsmhandle == nsm 470 && host->h_nsmstate != info->state) {
459 && host->h_nsmstate != info->state) { 471 host->h_nsmstate = info->state;
460 host->h_nsmstate = info->state; 472 host->h_state++;
461 host->h_state++; 473
462 474 nlm_get_host(host);
463 nlm_get_host(host); 475 mutex_unlock(&nlm_host_mutex);
464 mutex_unlock(&nlm_host_mutex); 476
465 477 if (host->h_server) {
466 if (host->h_server) { 478 /* We're server for this guy, just ditch
467 /* We're server for this guy, just ditch 479 * all the locks he held. */
468 * all the locks he held. */ 480 nlmsvc_free_host_resources(host);
469 nlmsvc_free_host_resources(host); 481 } else {
470 } else { 482 /* He's the server, initiate lock recovery. */
471 /* He's the server, initiate lock recovery. */ 483 nlmclnt_recovery(host);
472 nlmclnt_recovery(host);
473 }
474
475 nlm_release_host(host);
476 goto again;
477 } 484 }
485
486 nlm_release_host(host);
487 goto again;
478 } 488 }
479 } 489 }
480 mutex_unlock(&nlm_host_mutex); 490 mutex_unlock(&nlm_host_mutex);
@@ -497,13 +507,11 @@ nlm_shutdown_hosts(void)
497 507
498 /* First, make all hosts eligible for gc */ 508 /* First, make all hosts eligible for gc */
499 dprintk("lockd: nuking all hosts...\n"); 509 dprintk("lockd: nuking all hosts...\n");
500 for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) { 510 for_each_host(host, pos, chain, nlm_hosts) {
501 hlist_for_each_entry(host, pos, chain, h_hash) { 511 host->h_expires = jiffies - 1;
502 host->h_expires = jiffies - 1; 512 if (host->h_rpcclnt) {
503 if (host->h_rpcclnt) { 513 rpc_shutdown_client(host->h_rpcclnt);
504 rpc_shutdown_client(host->h_rpcclnt); 514 host->h_rpcclnt = NULL;
505 host->h_rpcclnt = NULL;
506 }
507 } 515 }
508 } 516 }
509 517
@@ -515,12 +523,10 @@ nlm_shutdown_hosts(void)
515 if (nrhosts) { 523 if (nrhosts) {
516 printk(KERN_WARNING "lockd: couldn't shutdown host module!\n"); 524 printk(KERN_WARNING "lockd: couldn't shutdown host module!\n");
517 dprintk("lockd: %d hosts left:\n", nrhosts); 525 dprintk("lockd: %d hosts left:\n", nrhosts);
518 for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) { 526 for_each_host(host, pos, chain, nlm_hosts) {
519 hlist_for_each_entry(host, pos, chain, h_hash) { 527 dprintk(" %s (cnt %d use %d exp %ld)\n",
520 dprintk(" %s (cnt %d use %d exp %ld)\n", 528 host->h_name, atomic_read(&host->h_count),
521 host->h_name, atomic_read(&host->h_count), 529 host->h_inuse, host->h_expires);
522 host->h_inuse, host->h_expires);
523 }
524 } 530 }
525 } 531 }
526} 532}
@@ -538,29 +544,26 @@ nlm_gc_hosts(void)
538 struct nlm_host *host; 544 struct nlm_host *host;
539 545
540 dprintk("lockd: host garbage collection\n"); 546 dprintk("lockd: host garbage collection\n");
541 for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) { 547 for_each_host(host, pos, chain, nlm_hosts)
542 hlist_for_each_entry(host, pos, chain, h_hash) 548 host->h_inuse = 0;
543 host->h_inuse = 0;
544 }
545 549
546 /* Mark all hosts that hold locks, blocks or shares */ 550 /* Mark all hosts that hold locks, blocks or shares */
547 nlmsvc_mark_resources(); 551 nlmsvc_mark_resources();
548 552
549 for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) { 553 for_each_host_safe(host, pos, next, chain, nlm_hosts) {
550 hlist_for_each_entry_safe(host, pos, next, chain, h_hash) { 554 if (atomic_read(&host->h_count) || host->h_inuse
551 if (atomic_read(&host->h_count) || host->h_inuse 555 || time_before(jiffies, host->h_expires)) {
552 || time_before(jiffies, host->h_expires)) { 556 dprintk("nlm_gc_hosts skipping %s "
553 dprintk("nlm_gc_hosts skipping %s (cnt %d use %d exp %ld)\n", 557 "(cnt %d use %d exp %ld)\n",
554 host->h_name, atomic_read(&host->h_count), 558 host->h_name, atomic_read(&host->h_count),
555 host->h_inuse, host->h_expires); 559 host->h_inuse, host->h_expires);
556 continue; 560 continue;
557 }
558 dprintk("lockd: delete host %s\n", host->h_name);
559 hlist_del_init(&host->h_hash);
560
561 nlm_destroy_host(host);
562 nrhosts--;
563 } 561 }
562 dprintk("lockd: delete host %s\n", host->h_name);
563 hlist_del_init(&host->h_hash);
564
565 nlm_destroy_host(host);
566 nrhosts--;
564 } 567 }
565 568
566 next_gc = jiffies + NLM_HOST_COLLECT; 569 next_gc = jiffies + NLM_HOST_COLLECT;