NLM: Clean up flow of control in make_socks() function
[safe/jmp/linux-2.6] / fs / lockd / svc.c
index f013aed..64f1c31 100644 (file)
@@ -35,7 +35,6 @@
 #include <linux/sunrpc/svcsock.h>
 #include <net/ip.h>
 #include <linux/lockd/lockd.h>
-#include <linux/lockd/sm_inter.h>
 #include <linux/nfs.h>
 
 #define NLMDBG_FACILITY                NLMDBG_SVC
@@ -45,7 +44,7 @@
 static struct svc_program      nlmsvc_program;
 
 struct nlmsvc_binding *                nlmsvc_ops;
-EXPORT_SYMBOL(nlmsvc_ops);
+EXPORT_SYMBOL_GPL(nlmsvc_ops);
 
 static DEFINE_MUTEX(nlmsvc_mutex);
 static unsigned int            nlmsvc_users;
@@ -54,13 +53,26 @@ static struct svc_rqst              *nlmsvc_rqst;
 unsigned long                  nlmsvc_timeout;
 
 /*
+ * If the kernel has IPv6 support available, always listen for
+ * both AF_INET and AF_INET6 requests.
+ */
+#if (defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)) && \
+       defined(CONFIG_SUNRPC_REGISTER_V4)
+static const sa_family_t       nlmsvc_family = AF_INET6;
+#else  /* (CONFIG_IPV6 || CONFIG_IPV6_MODULE) && CONFIG_SUNRPC_REGISTER_V4 */
+static const sa_family_t       nlmsvc_family = AF_INET;
+#endif /* (CONFIG_IPV6 || CONFIG_IPV6_MODULE) && CONFIG_SUNRPC_REGISTER_V4 */
+
+/*
  * These can be set at insmod time (useful for NFS as root filesystem),
  * and also changed through the sysctl interface.  -- Jamie Lokier, Aug 2003
  */
 static unsigned long           nlm_grace_period;
 static unsigned long           nlm_timeout = LOCKD_DFLT_TIMEO;
 static int                     nlm_udpport, nlm_tcpport;
-int                            nsm_use_hostnames = 0;
+
+/* RLIM_NOFILE defaults to 1024. That seems like a reasonable default here. */
+static unsigned int            nlm_max_connections = 1024;
 
 /*
  * Constants needed for the sysctl interface.
@@ -143,6 +155,9 @@ lockd(void *vrqstp)
                long timeout = MAX_SCHEDULE_TIMEOUT;
                RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]);
 
+               /* update sv_maxconn if it has changed */
+               rqstp->rq_server->sv_maxconn = nlm_max_connections;
+
                if (signalled()) {
                        flush_signals(current);
                        if (nlmsvc_ops) {
@@ -181,6 +196,7 @@ lockd(void *vrqstp)
        }
        flush_signals(current);
        cancel_delayed_work_sync(&grace_period_end);
+       locks_end_grace(&lockd_manager);
        if (nlmsvc_ops)
                nlmsvc_invalidate_all();
        nlm_shutdown_hosts();
@@ -188,47 +204,56 @@ lockd(void *vrqstp)
        return 0;
 }
 
+static int create_lockd_listener(struct svc_serv *serv, char *name,
+                                unsigned short port)
+{
+       struct svc_xprt *xprt;
+
+       xprt = svc_find_xprt(serv, name, 0, 0);
+       if (xprt == NULL)
+               return svc_create_xprt(serv, name, port, SVC_SOCK_DEFAULTS);
+
+       svc_xprt_put(xprt);
+       return 0;
+}
+
 /*
- * Make any sockets that are needed but not present.
- * If nlm_udpport or nlm_tcpport were set as module
- * options, make those sockets unconditionally
+ * Ensure there are active UDP and TCP listeners for lockd.
+ *
+ * Even if we have only TCP NFS mounts and/or TCP NFSDs, some
+ * local services (such as rpc.statd) still require UDP, and
+ * some NFS servers do not yet support NLM over TCP.
+ *
+ * Returns zero if all listeners are available; otherwise a
+ * negative errno value is returned.
  */
-static int make_socks(struct svc_serv *serv, int proto)
+static int make_socks(struct svc_serv *serv)
 {
        static int warned;
-       struct svc_xprt *xprt;
-       int err = 0;
-
-       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;
-       } else if (warned++ == 0)
+       int err;
+
+       err = create_lockd_listener(serv, "udp", nlm_udpport);
+       if (err < 0)
+               goto out_err;
+
+       err = create_lockd_listener(serv, "tcp", nlm_tcpport);
+       if (err < 0)
+               goto out_err;
+
+       warned = 0;
+       return 0;
+
+out_err:
+       if (warned++ == 0)
                printk(KERN_WARNING
-                      "lockd_up: makesock failed, error=%d\n", err);
+                       "lockd_up: makesock failed, error=%d\n", err);
        return err;
 }
 
 /*
  * Bring up the lockd process if it's not already up.
  */
-int
-lockd_up(int proto) /* Maybe add a 'family' option when IPv6 is supported ?? */
+int lockd_up(void)
 {
        struct svc_serv *serv;
        int             error = 0;
@@ -237,11 +262,8 @@ lockd_up(int proto) /* Maybe add a 'family' option when IPv6 is supported ?? */
        /*
         * Check whether we're already up and running.
         */
-       if (nlmsvc_rqst) {
-               if (proto)
-                       error = make_socks(nlmsvc_rqst->rq_server, proto);
+       if (nlmsvc_rqst)
                goto out;
-       }
 
        /*
         * Sanity check: if there's no pid,
@@ -252,13 +274,14 @@ lockd_up(int proto) /* Maybe add a 'family' option when IPv6 is supported ?? */
                        "lockd_up: no pid, %d users??\n", nlmsvc_users);
 
        error = -ENOMEM;
-       serv = svc_create(&nlmsvc_program, LOCKD_BUFSIZE, AF_INET, NULL);
+       serv = svc_create(&nlmsvc_program, LOCKD_BUFSIZE, nlmsvc_family, NULL);
        if (!serv) {
                printk(KERN_WARNING "lockd_up: create service failed\n");
                goto out;
        }
 
-       if ((error = make_socks(serv, proto)) < 0)
+       error = make_socks(serv);
+       if (error < 0)
                goto destroy_and_out;
 
        /*
@@ -275,6 +298,7 @@ lockd_up(int proto) /* Maybe add a 'family' option when IPv6 is supported ?? */
        }
 
        svc_sock_update_bufs(serv);
+       serv->sv_maxconn = nlm_max_connections;
 
        nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, serv->sv_name);
        if (IS_ERR(nlmsvc_task)) {
@@ -299,7 +323,7 @@ out:
        mutex_unlock(&nlmsvc_mutex);
        return error;
 }
-EXPORT_SYMBOL(lockd_up);
+EXPORT_SYMBOL_GPL(lockd_up);
 
 /*
  * Decrement the user count and bring down lockd if we're the last.
@@ -328,7 +352,7 @@ lockd_down(void)
 out:
        mutex_unlock(&nlmsvc_mutex);
 }
-EXPORT_SYMBOL(lockd_down);
+EXPORT_SYMBOL_GPL(lockd_down);
 
 #ifdef CONFIG_SYSCTL
 
@@ -484,6 +508,7 @@ module_param_call(nlm_udpport, param_set_port, param_get_int,
 module_param_call(nlm_tcpport, param_set_port, param_get_int,
                  &nlm_tcpport, 0644);
 module_param(nsm_use_hostnames, bool, 0644);
+module_param(nlm_max_connections, uint, 0644);
 
 /*
  * Initialising and terminating the module.