Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 229188
b: refs/heads/master
c: b113746
h: refs/heads/master
v: v3
  • Loading branch information
J. Bruce Fields authored and Trond Myklebust committed Dec 16, 2010
1 parent 93d762e commit 4c5cb1f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 53 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: bf2695516db982e90a22fc94f93491b481796bb1
refs/heads/master: b113746888c260a02f6ae1e92b0b9ef7e9c38993
107 changes: 55 additions & 52 deletions trunk/fs/lockd/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@
#define NLM_HOST_COLLECT (120 * HZ)

static struct hlist_head nlm_hosts[NLM_HOST_NRHASH];

#define for_each_host(host, pos, chain, table) \
for ((chain) = (table); \
(chain) < (table) + NLM_HOST_NRHASH; ++(chain)) \
hlist_for_each_entry((host), (pos), (chain), h_hash)

#define for_each_host_safe(host, pos, next, chain, table) \
for ((chain) = (table); \
(chain) < (table) + NLM_HOST_NRHASH; ++(chain)) \
hlist_for_each_entry_safe((host), (pos), (next), \
(chain), h_hash)

static unsigned long next_gc;
static int nrhosts;
static DEFINE_MUTEX(nlm_host_mutex);
Expand Down Expand Up @@ -453,28 +465,26 @@ void nlm_host_rebooted(const struct nlm_reboot *info)
* To avoid processing a host several times, we match the nsmstate.
*/
again: mutex_lock(&nlm_host_mutex);
for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) {
hlist_for_each_entry(host, pos, chain, h_hash) {
if (host->h_nsmhandle == nsm
&& host->h_nsmstate != info->state) {
host->h_nsmstate = info->state;
host->h_state++;

nlm_get_host(host);
mutex_unlock(&nlm_host_mutex);

if (host->h_server) {
/* We're server for this guy, just ditch
* all the locks he held. */
nlmsvc_free_host_resources(host);
} else {
/* He's the server, initiate lock recovery. */
nlmclnt_recovery(host);
}

nlm_release_host(host);
goto again;
for_each_host(host, pos, chain, nlm_hosts) {
if (host->h_nsmhandle == nsm
&& host->h_nsmstate != info->state) {
host->h_nsmstate = info->state;
host->h_state++;

nlm_get_host(host);
mutex_unlock(&nlm_host_mutex);

if (host->h_server) {
/* We're server for this guy, just ditch
* all the locks he held. */
nlmsvc_free_host_resources(host);
} else {
/* He's the server, initiate lock recovery. */
nlmclnt_recovery(host);
}

nlm_release_host(host);
goto again;
}
}
mutex_unlock(&nlm_host_mutex);
Expand All @@ -497,13 +507,11 @@ nlm_shutdown_hosts(void)

/* First, make all hosts eligible for gc */
dprintk("lockd: nuking all hosts...\n");
for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) {
hlist_for_each_entry(host, pos, chain, h_hash) {
host->h_expires = jiffies - 1;
if (host->h_rpcclnt) {
rpc_shutdown_client(host->h_rpcclnt);
host->h_rpcclnt = NULL;
}
for_each_host(host, pos, chain, nlm_hosts) {
host->h_expires = jiffies - 1;
if (host->h_rpcclnt) {
rpc_shutdown_client(host->h_rpcclnt);
host->h_rpcclnt = NULL;
}
}

Expand All @@ -515,12 +523,10 @@ nlm_shutdown_hosts(void)
if (nrhosts) {
printk(KERN_WARNING "lockd: couldn't shutdown host module!\n");
dprintk("lockd: %d hosts left:\n", nrhosts);
for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) {
hlist_for_each_entry(host, pos, chain, h_hash) {
dprintk(" %s (cnt %d use %d exp %ld)\n",
host->h_name, atomic_read(&host->h_count),
host->h_inuse, host->h_expires);
}
for_each_host(host, pos, chain, nlm_hosts) {
dprintk(" %s (cnt %d use %d exp %ld)\n",
host->h_name, atomic_read(&host->h_count),
host->h_inuse, host->h_expires);
}
}
}
Expand All @@ -538,29 +544,26 @@ nlm_gc_hosts(void)
struct nlm_host *host;

dprintk("lockd: host garbage collection\n");
for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) {
hlist_for_each_entry(host, pos, chain, h_hash)
host->h_inuse = 0;
}
for_each_host(host, pos, chain, nlm_hosts)
host->h_inuse = 0;

/* Mark all hosts that hold locks, blocks or shares */
nlmsvc_mark_resources();

for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) {
hlist_for_each_entry_safe(host, pos, next, chain, h_hash) {
if (atomic_read(&host->h_count) || host->h_inuse
|| time_before(jiffies, host->h_expires)) {
dprintk("nlm_gc_hosts skipping %s (cnt %d use %d exp %ld)\n",
host->h_name, atomic_read(&host->h_count),
host->h_inuse, host->h_expires);
continue;
}
dprintk("lockd: delete host %s\n", host->h_name);
hlist_del_init(&host->h_hash);

nlm_destroy_host(host);
nrhosts--;
for_each_host_safe(host, pos, next, chain, nlm_hosts) {
if (atomic_read(&host->h_count) || host->h_inuse
|| time_before(jiffies, host->h_expires)) {
dprintk("nlm_gc_hosts skipping %s "
"(cnt %d use %d exp %ld)\n",
host->h_name, atomic_read(&host->h_count),
host->h_inuse, host->h_expires);
continue;
}
dprintk("lockd: delete host %s\n", host->h_name);
hlist_del_init(&host->h_hash);

nlm_destroy_host(host);
nrhosts--;
}

next_gc = jiffies + NLM_HOST_COLLECT;
Expand Down

0 comments on commit 4c5cb1f

Please sign in to comment.