#include <linux/sunrpc/svc.h>
#include <linux/lockd/lockd.h>
#include <linux/lockd/sm_inter.h>
-#include <linux/mutex.h>
#define NLMDBG_FACILITY NLMDBG_HOSTCACHE
static struct nlm_host * nlm_hosts[NLM_HOST_NRHASH];
static unsigned long next_gc;
static int nrhosts;
-static DEFINE_MUTEX(nlm_host_mutex);
+static DECLARE_MUTEX(nlm_host_sema);
static void nlm_gc_hosts(void);
hash = NLM_ADDRHASH(sin->sin_addr.s_addr);
/* Lock hash table */
- mutex_lock(&nlm_host_mutex);
+ down(&nlm_host_sema);
if (time_after_eq(jiffies, next_gc))
nlm_gc_hosts();
nlm_hosts[hash] = host;
}
nlm_get_host(host);
- mutex_unlock(&nlm_host_mutex);
+ up(&nlm_host_sema);
return host;
}
}
host->h_version = version;
host->h_proto = proto;
host->h_rpcclnt = NULL;
- mutex_init(&host->h_mutex);
+ init_MUTEX(&host->h_sema);
host->h_nextrebind = jiffies + NLM_HOST_REBIND;
host->h_expires = jiffies + NLM_HOST_EXPIRE;
atomic_set(&host->h_count, 1);
init_waitqueue_head(&host->h_gracewait);
- init_rwsem(&host->h_rwsem);
host->h_state = 0; /* pseudo NSM state */
host->h_nsmstate = 0; /* real NSM state */
host->h_server = server;
nlm_hosts[hash] = host;
INIT_LIST_HEAD(&host->h_lockowners);
spin_lock_init(&host->h_lock);
- INIT_LIST_HEAD(&host->h_granted);
- INIT_LIST_HEAD(&host->h_reclaim);
if (++nrhosts > NLM_HOST_MAX)
next_gc = 0;
nohost:
- mutex_unlock(&nlm_host_mutex);
+ up(&nlm_host_sema);
return host;
}
* and return it
*/
int hash;
- mutex_lock(&nlm_host_mutex);
+ down(&nlm_host_sema);
for (hash = 0 ; hash < NLM_HOST_NRHASH; hash++) {
struct nlm_host *host, **hp;
for (hp = &nlm_hosts[hash]; (host = *hp) != 0; hp = &host->h_next) {
if (host->h_server &&
host->h_killed == 0) {
nlm_get_host(host);
- mutex_unlock(&nlm_host_mutex);
+ up(&nlm_host_sema);
return host;
}
}
}
- mutex_unlock(&nlm_host_mutex);
+ up(&nlm_host_sema);
return NULL;
}
(unsigned)ntohl(host->h_addr.sin_addr.s_addr));
/* Lock host handle */
- mutex_lock(&host->h_mutex);
+ down(&host->h_sema);
/* If we've already created an RPC client, check whether
* RPC rebind is required
xprt->resvport = 1; /* NLM requires a reserved port */
/* Existing NLM servers accept AUTH_UNIX only */
- clnt = rpc_new_client(xprt, host->h_name, &nlm_program,
+ clnt = rpc_create_client(xprt, host->h_name, &nlm_program,
host->h_version, RPC_AUTH_UNIX);
if (IS_ERR(clnt))
goto forgetit;
clnt->cl_autobind = 1; /* turn on pmap queries */
- clnt->cl_softrtry = 1; /* All queries are soft */
host->h_rpcclnt = clnt;
}
- mutex_unlock(&host->h_mutex);
+ up(&host->h_sema);
return clnt;
forgetit:
printk("lockd: couldn't create RPC handle for %s\n", host->h_name);
- mutex_unlock(&host->h_mutex);
+ up(&host->h_sema);
return NULL;
}
{
if (host != NULL) {
dprintk("lockd: release host %s\n", host->h_name);
+ atomic_dec(&host->h_count);
BUG_ON(atomic_read(&host->h_count) < 0);
- if (atomic_dec_and_test(&host->h_count)) {
- BUG_ON(!list_empty(&host->h_lockowners));
- BUG_ON(!list_empty(&host->h_granted));
- BUG_ON(!list_empty(&host->h_reclaim));
- }
}
}
int i;
dprintk("lockd: shutting down host module\n");
- mutex_lock(&nlm_host_mutex);
+ down(&nlm_host_sema);
/* First, make all hosts eligible for gc */
dprintk("lockd: nuking all hosts...\n");
/* Then, perform a garbage collection pass */
nlm_gc_hosts();
- mutex_unlock(&nlm_host_mutex);
+ up(&nlm_host_sema);
/* complain if any hosts are left */
if (nrhosts) {
rpc_destroy_client(host->h_rpcclnt);
}
}
+ BUG_ON(!list_empty(&host->h_lockowners));
kfree(host);
nrhosts--;
}