diff options
Diffstat (limited to 'fs/lockd')
-rw-r--r-- | fs/lockd/host.c | 107 |
1 files changed, 55 insertions, 52 deletions
diff --git a/fs/lockd/host.c b/fs/lockd/host.c index ed0c59fe23ce..cada3a12d557 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 | ||
28 | static struct hlist_head nlm_hosts[NLM_HOST_NRHASH]; | 28 | static 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 | |||
29 | static unsigned long next_gc; | 41 | static unsigned long next_gc; |
30 | static int nrhosts; | 42 | static int nrhosts; |
31 | static DEFINE_MUTEX(nlm_host_mutex); | 43 | static 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 | */ |
455 | again: mutex_lock(&nlm_host_mutex); | 467 | again: 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; |