]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/lockd/svc.c
lockd: Ensure NSM strings aren't longer than protocol allows
[linux-2.6-omap-h63xx.git] / fs / lockd / svc.c
index 26809325469cdc73bafa76dec33e52cfa046f548..38c2f0b1dd7d4094212af618ab74a56879005e6a 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/smp.h>
 #include <linux/smp_lock.h>
 #include <linux/mutex.h>
+#include <linux/freezer.h>
 
 #include <linux/sunrpc/types.h>
 #include <linux/sunrpc/stats.h>
@@ -73,20 +74,35 @@ static const unsigned long  nlm_timeout_min = 3;
 static const unsigned long     nlm_timeout_max = 20;
 static const int               nlm_port_min = 0, nlm_port_max = 65535;
 
+#ifdef CONFIG_SYSCTL
 static struct ctl_table_header * nlm_sysctl_table;
+#endif
 
-static unsigned long set_grace_period(void)
+static unsigned long get_lockd_grace_period(void)
 {
-       unsigned long grace_period;
-
        /* Note: nlm_timeout should always be nonzero */
        if (nlm_grace_period)
-               grace_period = ((nlm_grace_period + nlm_timeout - 1)
-                               / nlm_timeout) * nlm_timeout * HZ;
+               return roundup(nlm_grace_period, nlm_timeout) * HZ;
        else
-               grace_period = nlm_timeout * 5 * HZ;
+               return nlm_timeout * 5 * HZ;
+}
+
+unsigned long get_nfs_grace_period(void)
+{
+       unsigned long lockdgrace = get_lockd_grace_period();
+       unsigned long nfsdgrace = 0;
+
+       if (nlmsvc_ops)
+               nfsdgrace = nlmsvc_ops->get_grace_period();
+
+       return max(lockdgrace, nfsdgrace);
+}
+EXPORT_SYMBOL(get_nfs_grace_period);
+
+static unsigned long set_grace_period(void)
+{
        nlmsvc_grace_period = 1;
-       return grace_period + jiffies;
+       return get_nfs_grace_period() + jiffies;
 }
 
 static inline void clear_grace_period(void)
@@ -119,6 +135,7 @@ lockd(struct svc_rqst *rqstp)
        complete(&lockd_start_done);
 
        daemonize("lockd");
+       set_freezable();
 
        /* Process request with signals blocked, but allow SIGKILL.  */
        allow_signal(SIGKILL);
@@ -138,7 +155,7 @@ lockd(struct svc_rqst *rqstp)
         */
        while ((nlmsvc_users || !signalled()) && nlmsvc_pid == current->pid) {
                long timeout = MAX_SCHEDULE_TIMEOUT;
-               char buf[RPC_MAX_ADDRBUFLEN];
+               RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]);
 
                if (signalled()) {
                        flush_signals(current);
@@ -204,19 +221,6 @@ 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;
-}
-
 /*
  * Make any sockets that are needed but not present.
  * If nlm_udpport or nlm_tcpport were set as module
@@ -225,17 +229,25 @@ static int find_socket(struct svc_serv *serv, int proto)
 static int make_socks(struct svc_serv *serv, int proto)
 {
        static int warned;
+       struct svc_xprt *xprt;
        int err = 0;
 
-       if (proto == IPPROTO_UDP || nlm_udpport)
-               if (!find_socket(serv, IPPROTO_UDP))
-                       err = svc_makesock(serv, IPPROTO_UDP, nlm_udpport,
-                                               SVC_SOCK_DEFAULTS);
-       if (err >= 0 && (proto == IPPROTO_TCP || nlm_tcpport))
-               if (!find_socket(serv, IPPROTO_TCP))
-                       err = svc_makesock(serv, IPPROTO_TCP, nlm_tcpport,
-                                               SVC_SOCK_DEFAULTS);
-
+       if (proto == IPPROTO_UDP || nlm_udpport) {
+               xprt = svc_find_xprt(serv, "udp", 0, 0);
+               if (!xprt)
+                       err = svc_create_xprt(serv, "udp", nlm_udpport,
+                                             SVC_SOCK_DEFAULTS);
+               else
+                       svc_xprt_put(xprt);
+       }
+       if (err >= 0 && (proto == IPPROTO_TCP || nlm_tcpport)) {
+               xprt = svc_find_xprt(serv, "tcp", 0, 0);
+               if (!xprt)
+                       err = svc_create_xprt(serv, "tcp", nlm_tcpport,
+                                             SVC_SOCK_DEFAULTS);
+               else
+                       svc_xprt_put(xprt);
+       }
        if (err >= 0) {
                warned = 0;
                err = 0;
@@ -349,6 +361,8 @@ out:
 }
 EXPORT_SYMBOL(lockd_down);
 
+#ifdef CONFIG_SYSCTL
+
 /*
  * Sysctl parameters (same as module parameters, different interface).
  */
@@ -433,6 +447,8 @@ static ctl_table nlm_sysctl_root[] = {
        { .ctl_name = 0 }
 };
 
+#endif /* CONFIG_SYSCTL */
+
 /*
  * Module (and sysfs) parameters.
  */
@@ -506,15 +522,21 @@ module_param(nsm_use_hostnames, bool, 0644);
 
 static int __init init_nlm(void)
 {
+#ifdef CONFIG_SYSCTL
        nlm_sysctl_table = register_sysctl_table(nlm_sysctl_root);
        return nlm_sysctl_table ? 0 : -ENOMEM;
+#else
+       return 0;
+#endif
 }
 
 static void __exit exit_nlm(void)
 {
        /* FIXME: delete all NLM clients */
        nlm_shutdown_hosts();
+#ifdef CONFIG_SYSCTL
        unregister_sysctl_table(nlm_sysctl_table);
+#endif
 }
 
 module_init(init_nlm);