NLM: Refactor make_socks() function
[safe/jmp/linux-2.6] / fs / lockd / svc.c
index 56b0767..cf3899a 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) {
@@ -189,6 +204,19 @@ 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;
+}
+
 /*
  * Ensure there are active UDP and TCP listeners for lockd.
  *
@@ -202,23 +230,11 @@ lockd(void *vrqstp)
 static int make_socks(struct svc_serv *serv)
 {
        static int warned;
-       struct svc_xprt *xprt;
        int err = 0;
 
-       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) {
-               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);
-       }
+       err = create_lockd_listener(serv, "udp", nlm_udpport);
+       if (err >= 0)
+               err = create_lockd_listener(serv, "tcp", nlm_tcpport);
        if (err >= 0) {
                warned = 0;
                err = 0;
@@ -252,7 +268,7 @@ int lockd_up(void)
                        "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;
@@ -276,6 +292,7 @@ int lockd_up(void)
        }
 
        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)) {
@@ -300,7 +317,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.
@@ -329,7 +346,7 @@ lockd_down(void)
 out:
        mutex_unlock(&nlmsvc_mutex);
 }
-EXPORT_SYMBOL(lockd_down);
+EXPORT_SYMBOL_GPL(lockd_down);
 
 #ifdef CONFIG_SYSCTL
 
@@ -485,6 +502,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.