Merge nommu branch
[pandora-kernel.git] / fs / lockd / host.c
index c4c8601..703fb03 100644 (file)
@@ -16,6 +16,7 @@
 #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
 #define NLM_HOST_REBIND                (60 * 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_ADDR(sv)      (&(sv)->s_nlmclnt->cl_xprt->addr)
 
 static struct nlm_host *       nlm_hosts[NLM_HOST_NRHASH];
 static unsigned long           next_gc;
 static int                     nrhosts;
-static DECLARE_MUTEX(nlm_host_sema);
+static DEFINE_MUTEX(nlm_host_mutex);
 
 
 static void                    nlm_gc_hosts(void);
@@ -71,7 +71,7 @@ nlm_lookup_host(int server, struct sockaddr_in *sin,
        hash = NLM_ADDRHASH(sin->sin_addr.s_addr);
 
        /* Lock hash table */
-       down(&nlm_host_sema);
+       mutex_lock(&nlm_host_mutex);
 
        if (time_after_eq(jiffies, next_gc))
                nlm_gc_hosts();
@@ -91,7 +91,7 @@ nlm_lookup_host(int server, struct sockaddr_in *sin,
                                nlm_hosts[hash] = host;
                        }
                        nlm_get_host(host);
-                       up(&nlm_host_sema);
+                       mutex_unlock(&nlm_host_mutex);
                        return host;
                }
        }
@@ -111,11 +111,12 @@ nlm_lookup_host(int server, struct sockaddr_in *sin,
        host->h_version    = version;
        host->h_proto      = proto;
        host->h_rpcclnt    = NULL;
-       init_MUTEX(&host->h_sema);
+       mutex_init(&host->h_mutex);
        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;
@@ -123,12 +124,14 @@ nlm_lookup_host(int server, struct sockaddr_in *sin,
        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:
-       up(&nlm_host_sema);
+       mutex_unlock(&nlm_host_mutex);
        return host;
 }
 
@@ -139,19 +142,19 @@ nlm_find_client(void)
         * and return it
         */
        int hash;
-       down(&nlm_host_sema);
+       mutex_lock(&nlm_host_mutex);
        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);
-                               up(&nlm_host_sema);
+                               mutex_unlock(&nlm_host_mutex);
                                return host;
                        }
                }
        }
-       up(&nlm_host_sema);
+       mutex_unlock(&nlm_host_mutex);
        return NULL;
 }
 
@@ -163,50 +166,55 @@ struct rpc_clnt *
 nlm_bind_host(struct nlm_host *host)
 {
        struct rpc_clnt *clnt;
-       struct rpc_xprt *xprt;
 
        dprintk("lockd: nlm_bind_host(%08x)\n",
                        (unsigned)ntohl(host->h_addr.sin_addr.s_addr));
 
        /* Lock host handle */
-       down(&host->h_sema);
+       mutex_lock(&host->h_mutex);
 
        /* If we've already created an RPC client, check whether
         * RPC rebind is required
         */
        if ((clnt = host->h_rpcclnt) != NULL) {
-               xprt = clnt->cl_xprt;
                if (time_after_eq(jiffies, host->h_nextrebind)) {
-                       clnt->cl_port = 0;
+                       rpc_force_rebind(clnt);
                        host->h_nextrebind = jiffies + NLM_HOST_REBIND;
                        dprintk("lockd: next rebind in %ld jiffies\n",
                                        host->h_nextrebind - jiffies);
                }
        } else {
-               xprt = xprt_create_proto(host->h_proto, &host->h_addr, NULL);
-               if (IS_ERR(xprt))
-                       goto forgetit;
-
-               xprt_set_timeout(&xprt->timeout, 5, nlmsvc_timeout);
-               xprt->resvport = 1;     /* NLM requires a reserved port */
-
-               /* Existing NLM servers accept AUTH_UNIX only */
-               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 */
-
-               host->h_rpcclnt = clnt;
+               unsigned long increment = nlmsvc_timeout * HZ;
+               struct rpc_timeout timeparms = {
+                       .to_initval     = increment,
+                       .to_increment   = increment,
+                       .to_maxval      = increment * 6UL,
+                       .to_retries     = 5U,
+               };
+               struct rpc_create_args args = {
+                       .protocol       = host->h_proto,
+                       .address        = (struct sockaddr *)&host->h_addr,
+                       .addrsize       = sizeof(host->h_addr),
+                       .timeout        = &timeparms,
+                       .servername     = host->h_name,
+                       .program        = &nlm_program,
+                       .version        = host->h_version,
+                       .authflavor     = RPC_AUTH_UNIX,
+                       .flags          = (RPC_CLNT_CREATE_HARDRTRY |
+                                          RPC_CLNT_CREATE_AUTOBIND),
+               };
+
+               clnt = rpc_create(&args);
+               if (!IS_ERR(clnt))
+                       host->h_rpcclnt = clnt;
+               else {
+                       printk("lockd: couldn't create RPC handle for %s\n", host->h_name);
+                       clnt = NULL;
+               }
        }
 
-       up(&host->h_sema);
+       mutex_unlock(&host->h_mutex);
        return clnt;
-
-forgetit:
-       printk("lockd: couldn't create RPC handle for %s\n", host->h_name);
-       up(&host->h_sema);
-       return NULL;
 }
 
 /*
@@ -217,7 +225,7 @@ nlm_rebind_host(struct nlm_host *host)
 {
        dprintk("lockd: rebind host %s\n", host->h_name);
        if (host->h_rpcclnt && time_after_eq(jiffies, host->h_nextrebind)) {
-               host->h_rpcclnt->cl_port = 0;
+               rpc_force_rebind(host->h_rpcclnt);
                host->h_nextrebind = jiffies + NLM_HOST_REBIND;
        }
 }
@@ -242,8 +250,12 @@ void nlm_release_host(struct nlm_host *host)
 {
        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));
+               }
        }
 }
 
@@ -258,7 +270,7 @@ nlm_shutdown_hosts(void)
        int             i;
 
        dprintk("lockd: shutting down host module\n");
-       down(&nlm_host_sema);
+       mutex_lock(&nlm_host_mutex);
 
        /* First, make all hosts eligible for gc */
        dprintk("lockd: nuking all hosts...\n");
@@ -269,7 +281,7 @@ nlm_shutdown_hosts(void)
 
        /* Then, perform a garbage collection pass */
        nlm_gc_hosts();
-       up(&nlm_host_sema);
+       mutex_unlock(&nlm_host_mutex);
 
        /* complain if any hosts are left */
        if (nrhosts) {
@@ -331,7 +343,6 @@ nlm_gc_hosts(void)
                                        rpc_destroy_client(host->h_rpcclnt);
                                }
                        }
-                       BUG_ON(!list_empty(&host->h_lockowners));
                        kfree(host);
                        nrhosts--;
                }