]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - fs/lockd/svc.c
[PATCH] knfsd: when looking up a lockd host, pass hostname & length
[linux-2.6.git] / fs / lockd / svc.c
index 5e85bde6c123e89fb271706ffeaf2e99080dca32..3cc369e5693f2d9af1c34e605c1ba2c615a21eae 100644 (file)
@@ -12,7 +12,6 @@
  * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/sysctl.h>
 #include <linux/slab.h>
 #include <linux/smp.h>
 #include <linux/smp_lock.h>
+#include <linux/mutex.h>
 
 #include <linux/sunrpc/types.h>
 #include <linux/sunrpc/stats.h>
 #include <linux/sunrpc/clnt.h>
 #include <linux/sunrpc/svc.h>
 #include <linux/sunrpc/svcsock.h>
+#include <net/ip.h>
 #include <linux/lockd/lockd.h>
 #include <linux/nfs.h>
 
@@ -43,13 +44,14 @@ static struct svc_program   nlmsvc_program;
 struct nlmsvc_binding *                nlmsvc_ops;
 EXPORT_SYMBOL(nlmsvc_ops);
 
-static DECLARE_MUTEX(nlmsvc_sema);
+static DEFINE_MUTEX(nlmsvc_mutex);
 static unsigned int            nlmsvc_users;
 static pid_t                   nlmsvc_pid;
+static struct svc_serv         *nlmsvc_serv;
 int                            nlmsvc_grace_period;
 unsigned long                  nlmsvc_timeout;
 
-static DECLARE_MUTEX_LOCKED(lockd_start);
+static DECLARE_COMPLETION(lockd_start_done);
 static DECLARE_WAIT_QUEUE_HEAD(lockd_exit);
 
 /*
@@ -96,7 +98,6 @@ static inline void clear_grace_period(void)
 static void
 lockd(struct svc_rqst *rqstp)
 {
-       struct svc_serv *serv = rqstp->rq_server;
        int             err = 0;
        unsigned long grace_period_expire;
 
@@ -112,7 +113,8 @@ lockd(struct svc_rqst *rqstp)
         * Let our maker know we're running.
         */
        nlmsvc_pid = current->pid;
-       up(&lockd_start);
+       nlmsvc_serv = rqstp->rq_server;
+       complete(&lockd_start_done);
 
        daemonize("lockd");
 
@@ -161,7 +163,7 @@ lockd(struct svc_rqst *rqstp)
                 * Find a socket with data available and call its
                 * recvfrom routine.
                 */
-               err = svc_recv(serv, rqstp, timeout);
+               err = svc_recv(rqstp, timeout);
                if (err == -EAGAIN || err == -EINTR)
                        continue;
                if (err < 0) {
@@ -174,7 +176,7 @@ lockd(struct svc_rqst *rqstp)
                dprintk("lockd: request from %08x\n",
                        (unsigned)ntohl(rqstp->rq_addr.sin_addr.s_addr));
 
-               svc_process(serv, rqstp);
+               svc_process(rqstp);
 
        }
 
@@ -189,6 +191,7 @@ lockd(struct svc_rqst *rqstp)
                        nlmsvc_invalidate_all();
                nlm_shutdown_hosts();
                nlmsvc_pid = 0;
+               nlmsvc_serv = NULL;
        } else
                printk(KERN_DEBUG
                        "lockd: new process, skipping host shutdown\n");
@@ -205,54 +208,77 @@ lockd(struct svc_rqst *rqstp)
        module_put_and_exit(0);
 }
 
+
+static int find_socket(struct svc_serv *serv, int proto)
+{
+       struct svc_sock *svsk;
+       int found = 0;
+       list_for_each_entry(svsk, &serv->sv_permsocks, sk_list)
+               if (svsk->sk_sk->sk_protocol == proto) {
+                       found = 1;
+                       break;
+               }
+       return found;
+}
+
+static int make_socks(struct svc_serv *serv, int proto)
+{
+       /* Make any sockets that are needed but not present.
+        * If nlm_udpport or nlm_tcpport were set as module
+        * options, make those sockets unconditionally
+        */
+       static int              warned;
+       int err = 0;
+       if (proto == IPPROTO_UDP || nlm_udpport)
+               if (!find_socket(serv, IPPROTO_UDP))
+                       err = svc_makesock(serv, IPPROTO_UDP, nlm_udpport);
+       if (err == 0 && (proto == IPPROTO_TCP || nlm_tcpport))
+               if (!find_socket(serv, IPPROTO_TCP))
+                       err= svc_makesock(serv, IPPROTO_TCP, nlm_tcpport);
+       if (!err)
+               warned = 0;
+       else if (warned++ == 0)
+               printk(KERN_WARNING
+                      "lockd_up: makesock failed, error=%d\n", err);
+       return err;
+}
+
 /*
  * Bring up the lockd process if it's not already up.
  */
 int
-lockd_up(void)
+lockd_up(int proto) /* Maybe add a 'family' option when IPv6 is supported ?? */
 {
-       static int              warned;
        struct svc_serv *       serv;
        int                     error = 0;
 
-       down(&nlmsvc_sema);
-       /*
-        * Unconditionally increment the user count ... this is
-        * the number of clients who _want_ a lockd process.
-        */
-       nlmsvc_users++; 
+       mutex_lock(&nlmsvc_mutex);
        /*
         * Check whether we're already up and running.
         */
-       if (nlmsvc_pid)
+       if (nlmsvc_pid) {
+               if (proto)
+                       error = make_socks(nlmsvc_serv, proto);
                goto out;
+       }
 
        /*
         * Sanity check: if there's no pid,
         * we should be the first user ...
         */
-       if (nlmsvc_users > 1)
+       if (nlmsvc_users)
                printk(KERN_WARNING
                        "lockd_up: no pid, %d users??\n", nlmsvc_users);
 
        error = -ENOMEM;
-       serv = svc_create(&nlmsvc_program, LOCKD_BUFSIZE);
+       serv = svc_create(&nlmsvc_program, LOCKD_BUFSIZE, NULL);
        if (!serv) {
                printk(KERN_WARNING "lockd_up: create service failed\n");
                goto out;
        }
 
-       if ((error = svc_makesock(serv, IPPROTO_UDP, nlm_udpport)) < 0 
-#ifdef CONFIG_NFSD_TCP
-        || (error = svc_makesock(serv, IPPROTO_TCP, nlm_tcpport)) < 0
-#endif
-               ) {
-               if (warned++ == 0) 
-                       printk(KERN_WARNING
-                               "lockd_up: makesock failed, error=%d\n", error);
+       if ((error = make_socks(serv, proto)) < 0)
                goto destroy_and_out;
-       } 
-       warned = 0;
 
        /*
         * Create the kernel thread and wait for it to start.
@@ -263,7 +289,7 @@ lockd_up(void)
                        "lockd_up: create thread failed, error=%d\n", error);
                goto destroy_and_out;
        }
-       down(&lockd_start);
+       wait_for_completion(&lockd_start_done);
 
        /*
         * Note: svc_serv structures have an initial use count of 1,
@@ -272,7 +298,9 @@ lockd_up(void)
 destroy_and_out:
        svc_destroy(serv);
 out:
-       up(&nlmsvc_sema);
+       if (!error)
+               nlmsvc_users++;
+       mutex_unlock(&nlmsvc_mutex);
        return error;
 }
 EXPORT_SYMBOL(lockd_up);
@@ -285,7 +313,7 @@ lockd_down(void)
 {
        static int warned;
 
-       down(&nlmsvc_sema);
+       mutex_lock(&nlmsvc_mutex);
        if (nlmsvc_users) {
                if (--nlmsvc_users)
                        goto out;
@@ -315,7 +343,7 @@ lockd_down(void)
        recalc_sigpending();
        spin_unlock_irq(&current->sighand->siglock);
 out:
-       up(&nlmsvc_sema);
+       mutex_unlock(&nlmsvc_mutex);
 }
 EXPORT_SYMBOL(lockd_down);