[PATCH] knfsd: lockd: make the hash chains use a hlist_node
Get rid of the home-grown singly linked lists for the nlm_host hash table. Signed-off-by: Olaf Kirch <okir@suse.de> Signed-off-by: Neil Brown <neilb@suse.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
parent
9502c52259
commit
0cea32761a
|
@ -27,7 +27,7 @@
|
||||||
#define NLM_HOST_EXPIRE ((nrhosts > NLM_HOST_MAX)? 300 * HZ : 120 * HZ)
|
#define NLM_HOST_EXPIRE ((nrhosts > NLM_HOST_MAX)? 300 * HZ : 120 * HZ)
|
||||||
#define NLM_HOST_COLLECT ((nrhosts > NLM_HOST_MAX)? 120 * HZ : 60 * HZ)
|
#define NLM_HOST_COLLECT ((nrhosts > NLM_HOST_MAX)? 120 * HZ : 60 * HZ)
|
||||||
|
|
||||||
static struct nlm_host * nlm_hosts[NLM_HOST_NRHASH];
|
static struct hlist_head nlm_hosts[NLM_HOST_NRHASH];
|
||||||
static unsigned long next_gc;
|
static unsigned long next_gc;
|
||||||
static int nrhosts;
|
static int nrhosts;
|
||||||
static DEFINE_MUTEX(nlm_host_mutex);
|
static DEFINE_MUTEX(nlm_host_mutex);
|
||||||
|
@ -69,7 +69,9 @@ nlm_lookup_host(int server, const struct sockaddr_in *sin,
|
||||||
const char *hostname,
|
const char *hostname,
|
||||||
int hostname_len)
|
int hostname_len)
|
||||||
{
|
{
|
||||||
struct nlm_host *host, **hp;
|
struct hlist_head *chain;
|
||||||
|
struct hlist_node *pos;
|
||||||
|
struct nlm_host *host;
|
||||||
struct nsm_handle *nsm = NULL;
|
struct nsm_handle *nsm = NULL;
|
||||||
int hash;
|
int hash;
|
||||||
|
|
||||||
|
@ -95,7 +97,8 @@ nlm_lookup_host(int server, const struct sockaddr_in *sin,
|
||||||
* different NLM rpc_clients into one single nlm_host object.
|
* different NLM rpc_clients into one single nlm_host object.
|
||||||
* This would allow us to have one nlm_host per address.
|
* This would allow us to have one nlm_host per address.
|
||||||
*/
|
*/
|
||||||
for (hp = &nlm_hosts[hash]; (host = *hp) != 0; hp = &host->h_next) {
|
chain = &nlm_hosts[hash];
|
||||||
|
hlist_for_each_entry(host, pos, chain, h_hash) {
|
||||||
if (!nlm_cmp_addr(&host->h_addr, sin))
|
if (!nlm_cmp_addr(&host->h_addr, sin))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -110,15 +113,16 @@ nlm_lookup_host(int server, const struct sockaddr_in *sin,
|
||||||
if (host->h_server != server)
|
if (host->h_server != server)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (hp != nlm_hosts + hash) {
|
/* Move to head of hash chain. */
|
||||||
*hp = host->h_next;
|
hlist_del(&host->h_hash);
|
||||||
host->h_next = nlm_hosts[hash];
|
hlist_add_head(&host->h_hash, chain);
|
||||||
nlm_hosts[hash] = host;
|
|
||||||
}
|
|
||||||
nlm_get_host(host);
|
nlm_get_host(host);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
host = NULL;
|
||||||
|
|
||||||
/* Sadly, the host isn't in our hash table yet. See if
|
/* Sadly, the host isn't in our hash table yet. See if
|
||||||
* we have an NSM handle for it. If not, create one.
|
* we have an NSM handle for it. If not, create one.
|
||||||
*/
|
*/
|
||||||
|
@ -146,8 +150,7 @@ nlm_lookup_host(int server, const struct sockaddr_in *sin,
|
||||||
host->h_nsmstate = 0; /* real NSM state */
|
host->h_nsmstate = 0; /* real NSM state */
|
||||||
host->h_nsmhandle = nsm;
|
host->h_nsmhandle = nsm;
|
||||||
host->h_server = server;
|
host->h_server = server;
|
||||||
host->h_next = nlm_hosts[hash];
|
hlist_add_head(&host->h_hash, chain);
|
||||||
nlm_hosts[hash] = host;
|
|
||||||
INIT_LIST_HEAD(&host->h_lockowners);
|
INIT_LIST_HEAD(&host->h_lockowners);
|
||||||
spin_lock_init(&host->h_lock);
|
spin_lock_init(&host->h_lock);
|
||||||
INIT_LIST_HEAD(&host->h_granted);
|
INIT_LIST_HEAD(&host->h_granted);
|
||||||
|
@ -164,14 +167,17 @@ out:
|
||||||
struct nlm_host *
|
struct nlm_host *
|
||||||
nlm_find_client(void)
|
nlm_find_client(void)
|
||||||
{
|
{
|
||||||
|
struct hlist_head *chain;
|
||||||
|
struct hlist_node *pos;
|
||||||
|
|
||||||
/* find a nlm_host for a client for which h_killed == 0.
|
/* find a nlm_host for a client for which h_killed == 0.
|
||||||
* and return it
|
* and return it
|
||||||
*/
|
*/
|
||||||
int hash;
|
|
||||||
mutex_lock(&nlm_host_mutex);
|
mutex_lock(&nlm_host_mutex);
|
||||||
for (hash = 0 ; hash < NLM_HOST_NRHASH; hash++) {
|
for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) {
|
||||||
struct nlm_host *host, **hp;
|
struct nlm_host *host;
|
||||||
for (hp = &nlm_hosts[hash]; (host = *hp) != 0; hp = &host->h_next) {
|
|
||||||
|
hlist_for_each_entry(host, pos, chain, h_hash) {
|
||||||
if (host->h_server &&
|
if (host->h_server &&
|
||||||
host->h_killed == 0) {
|
host->h_killed == 0) {
|
||||||
nlm_get_host(host);
|
nlm_get_host(host);
|
||||||
|
@ -294,9 +300,10 @@ void nlm_host_rebooted(const struct sockaddr_in *sin,
|
||||||
const char *hostname, int hostname_len,
|
const char *hostname, int hostname_len,
|
||||||
u32 new_state)
|
u32 new_state)
|
||||||
{
|
{
|
||||||
|
struct hlist_head *chain;
|
||||||
|
struct hlist_node *pos;
|
||||||
struct nsm_handle *nsm;
|
struct nsm_handle *nsm;
|
||||||
struct nlm_host *host, **hp;
|
struct nlm_host *host;
|
||||||
int hash;
|
|
||||||
|
|
||||||
dprintk("lockd: nlm_host_rebooted(%s, %u.%u.%u.%u)\n",
|
dprintk("lockd: nlm_host_rebooted(%s, %u.%u.%u.%u)\n",
|
||||||
hostname, NIPQUAD(sin->sin_addr));
|
hostname, NIPQUAD(sin->sin_addr));
|
||||||
|
@ -315,8 +322,8 @@ void nlm_host_rebooted(const struct sockaddr_in *sin,
|
||||||
* To avoid processing a host several times, we match the nsmstate.
|
* To avoid processing a host several times, we match the nsmstate.
|
||||||
*/
|
*/
|
||||||
again: mutex_lock(&nlm_host_mutex);
|
again: mutex_lock(&nlm_host_mutex);
|
||||||
for (hash = 0; hash < NLM_HOST_NRHASH; hash++) {
|
for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) {
|
||||||
for (hp = &nlm_hosts[hash]; (host = *hp); hp = &host->h_next) {
|
hlist_for_each_entry(host, pos, chain, h_hash) {
|
||||||
if (host->h_nsmhandle == nsm
|
if (host->h_nsmhandle == nsm
|
||||||
&& host->h_nsmstate != new_state) {
|
&& host->h_nsmstate != new_state) {
|
||||||
host->h_nsmstate = new_state;
|
host->h_nsmstate = new_state;
|
||||||
|
@ -350,16 +357,17 @@ again: mutex_lock(&nlm_host_mutex);
|
||||||
void
|
void
|
||||||
nlm_shutdown_hosts(void)
|
nlm_shutdown_hosts(void)
|
||||||
{
|
{
|
||||||
|
struct hlist_head *chain;
|
||||||
|
struct hlist_node *pos;
|
||||||
struct nlm_host *host;
|
struct nlm_host *host;
|
||||||
int i;
|
|
||||||
|
|
||||||
dprintk("lockd: shutting down host module\n");
|
dprintk("lockd: shutting down host module\n");
|
||||||
mutex_lock(&nlm_host_mutex);
|
mutex_lock(&nlm_host_mutex);
|
||||||
|
|
||||||
/* First, make all hosts eligible for gc */
|
/* First, make all hosts eligible for gc */
|
||||||
dprintk("lockd: nuking all hosts...\n");
|
dprintk("lockd: nuking all hosts...\n");
|
||||||
for (i = 0; i < NLM_HOST_NRHASH; i++) {
|
for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) {
|
||||||
for (host = nlm_hosts[i]; host; host = host->h_next)
|
hlist_for_each_entry(host, pos, chain, h_hash)
|
||||||
host->h_expires = jiffies - 1;
|
host->h_expires = jiffies - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,8 +379,8 @@ nlm_shutdown_hosts(void)
|
||||||
if (nrhosts) {
|
if (nrhosts) {
|
||||||
printk(KERN_WARNING "lockd: couldn't shutdown host module!\n");
|
printk(KERN_WARNING "lockd: couldn't shutdown host module!\n");
|
||||||
dprintk("lockd: %d hosts left:\n", nrhosts);
|
dprintk("lockd: %d hosts left:\n", nrhosts);
|
||||||
for (i = 0; i < NLM_HOST_NRHASH; i++) {
|
for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) {
|
||||||
for (host = nlm_hosts[i]; host; host = host->h_next) {
|
hlist_for_each_entry(host, pos, chain, h_hash) {
|
||||||
dprintk(" %s (cnt %d use %d exp %ld)\n",
|
dprintk(" %s (cnt %d use %d exp %ld)\n",
|
||||||
host->h_name, atomic_read(&host->h_count),
|
host->h_name, atomic_read(&host->h_count),
|
||||||
host->h_inuse, host->h_expires);
|
host->h_inuse, host->h_expires);
|
||||||
|
@ -389,32 +397,31 @@ nlm_shutdown_hosts(void)
|
||||||
static void
|
static void
|
||||||
nlm_gc_hosts(void)
|
nlm_gc_hosts(void)
|
||||||
{
|
{
|
||||||
struct nlm_host **q, *host;
|
struct hlist_head *chain;
|
||||||
|
struct hlist_node *pos, *next;
|
||||||
|
struct nlm_host *host;
|
||||||
struct rpc_clnt *clnt;
|
struct rpc_clnt *clnt;
|
||||||
int i;
|
|
||||||
|
|
||||||
dprintk("lockd: host garbage collection\n");
|
dprintk("lockd: host garbage collection\n");
|
||||||
for (i = 0; i < NLM_HOST_NRHASH; i++) {
|
for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) {
|
||||||
for (host = nlm_hosts[i]; host; host = host->h_next)
|
hlist_for_each_entry(host, pos, chain, h_hash)
|
||||||
host->h_inuse = 0;
|
host->h_inuse = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mark all hosts that hold locks, blocks or shares */
|
/* Mark all hosts that hold locks, blocks or shares */
|
||||||
nlmsvc_mark_resources();
|
nlmsvc_mark_resources();
|
||||||
|
|
||||||
for (i = 0; i < NLM_HOST_NRHASH; i++) {
|
for (chain = nlm_hosts; chain < nlm_hosts + NLM_HOST_NRHASH; ++chain) {
|
||||||
q = &nlm_hosts[i];
|
hlist_for_each_entry_safe(host, pos, next, chain, h_hash) {
|
||||||
while ((host = *q) != NULL) {
|
|
||||||
if (atomic_read(&host->h_count) || host->h_inuse
|
if (atomic_read(&host->h_count) || host->h_inuse
|
||||||
|| time_before(jiffies, host->h_expires)) {
|
|| time_before(jiffies, host->h_expires)) {
|
||||||
dprintk("nlm_gc_hosts skipping %s (cnt %d use %d exp %ld)\n",
|
dprintk("nlm_gc_hosts skipping %s (cnt %d use %d exp %ld)\n",
|
||||||
host->h_name, atomic_read(&host->h_count),
|
host->h_name, atomic_read(&host->h_count),
|
||||||
host->h_inuse, host->h_expires);
|
host->h_inuse, host->h_expires);
|
||||||
q = &host->h_next;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
dprintk("lockd: delete host %s\n", host->h_name);
|
dprintk("lockd: delete host %s\n", host->h_name);
|
||||||
*q = host->h_next;
|
hlist_del_init(&host->h_hash);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unmonitor unless host was invalidated (i.e. lockd restarted)
|
* Unmonitor unless host was invalidated (i.e. lockd restarted)
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
* Lockd host handle (used both by the client and server personality).
|
* Lockd host handle (used both by the client and server personality).
|
||||||
*/
|
*/
|
||||||
struct nlm_host {
|
struct nlm_host {
|
||||||
struct nlm_host * h_next; /* linked list (hash table) */
|
struct hlist_node h_hash; /* doubly linked list */
|
||||||
struct sockaddr_in h_addr; /* peer address */
|
struct sockaddr_in h_addr; /* peer address */
|
||||||
struct rpc_clnt * h_rpcclnt; /* RPC client to talk to peer */
|
struct rpc_clnt * h_rpcclnt; /* RPC client to talk to peer */
|
||||||
char * h_name; /* remote hostname */
|
char * h_name; /* remote hostname */
|
||||||
|
|
Loading…
Reference in a new issue