15 #include <linux/module.h>
17 #include <linux/sysctl.h>
20 #include <linux/sched.h>
21 #include <linux/errno.h>
23 #include <linux/uio.h>
36 #include <linux/nfs.h>
40 #define NLMDBG_FACILITY NLMDBG_SVC
41 #define LOCKD_BUFSIZE (1024 + NLMSVC_XDRSIZE)
42 #define ALLOWED_SIGS (sigmask(SIGKILL))
50 static unsigned int nlmsvc_users;
61 static unsigned long nlm_grace_period;
62 static unsigned long nlm_timeout = LOCKD_DFLT_TIMEO;
63 static int nlm_udpport, nlm_tcpport;
66 static unsigned int nlm_max_connections = 1024;
71 static const unsigned long nlm_grace_period_min = 0;
72 static const unsigned long nlm_grace_period_max = 240;
73 static const unsigned long nlm_timeout_min = 3;
74 static const unsigned long nlm_timeout_max = 20;
75 static const int nlm_port_min = 0, nlm_port_max = 65535;
81 static unsigned long get_lockd_grace_period(
void)
85 return roundup(nlm_grace_period, nlm_timeout) *
HZ;
87 return nlm_timeout * 5 *
HZ;
100 static void set_grace_period(
struct net *
net)
102 unsigned long grace_period = get_lockd_grace_period();
110 static void restart_grace(
void)
119 set_grace_period(net);
138 dprintk(
"NFS locking service started (ver " LOCKD_VERSION
").\n");
141 nlm_timeout = LOCKD_DFLT_TIMEO;
153 rqstp->
rq_server->sv_maxconn = nlm_max_connections;
170 dprintk(
"lockd: request from %s\n",
182 static int create_lockd_listener(
struct svc_serv *serv,
const char *
name,
184 const unsigned short port)
196 static int create_lockd_family(
struct svc_serv *serv,
struct net *net,
201 err = create_lockd_listener(serv,
"udp", net, family, nlm_udpport);
205 return create_lockd_listener(serv,
"tcp", net, family, nlm_tcpport);
218 static int make_socks(
struct svc_serv *serv,
struct net *net)
223 err = create_lockd_family(serv, net,
PF_INET);
227 err = create_lockd_family(serv, net,
PF_INET6);
237 "lockd_up: makesock failed, error=%d\n", err);
241 static int lockd_up_net(
struct svc_serv *serv,
struct net *net)
253 error = make_socks(serv, net);
256 set_grace_period(net);
257 dprintk(
"lockd_up_net: per-net data created; net=%p\n", net);
267 static void lockd_down_net(
struct svc_serv *serv,
struct net *net)
277 dprintk(
"lockd_down_net: per-net data destroyed; net=%p\n", net);
286 static int lockd_start_svc(
struct svc_serv *serv)
297 if (IS_ERR(nlmsvc_rqst)) {
298 error = PTR_ERR(nlmsvc_rqst);
300 "lockd_up: svc_rqst allocation failed, error=%d\n",
309 if (IS_ERR(nlmsvc_task)) {
310 error = PTR_ERR(nlmsvc_task);
312 "lockd_up: kthread_run failed, error=%d\n", error);
315 dprintk(
"lockd_up: service started\n");
326 static struct svc_serv *lockd_create_svc(
void)
348 "lockd_up: no pid, %d users??\n", nlmsvc_users);
355 dprintk(
"lockd_up: service created\n");
369 serv = lockd_create_svc();
371 error = PTR_ERR(serv);
375 error = lockd_up_net(serv, net);
379 error = lockd_start_svc(serv);
395 lockd_down_net(serv, net);
407 lockd_down_net(nlmsvc_rqst->
rq_server, net);
422 dprintk(
"lockd_down: service stopped\n");
424 dprintk(
"lockd_down: service destroyed\n");
441 .data = &nlm_grace_period,
442 .maxlen =
sizeof(
unsigned long),
445 .extra1 = (
unsigned long *) &nlm_grace_period_min,
446 .extra2 = (
unsigned long *) &nlm_grace_period_max,
449 .procname =
"nlm_timeout",
450 .data = &nlm_timeout,
451 .maxlen =
sizeof(
unsigned long),
454 .extra1 = (
unsigned long *) &nlm_timeout_min,
455 .extra2 = (
unsigned long *) &nlm_timeout_max,
458 .procname =
"nlm_udpport",
459 .data = &nlm_udpport,
460 .maxlen =
sizeof(
int),
463 .extra1 = (
int *) &nlm_port_min,
464 .extra2 = (
int *) &nlm_port_max,
467 .procname =
"nlm_tcpport",
468 .data = &nlm_tcpport,
469 .maxlen =
sizeof(
int),
472 .extra1 = (
int *) &nlm_port_min,
473 .extra2 = (
int *) &nlm_port_max,
476 .procname =
"nsm_use_hostnames",
478 .maxlen =
sizeof(
int),
483 .procname =
"nsm_local_state",
485 .maxlen =
sizeof(
int),
496 .child = nlm_sysctls,
505 .child = nlm_sysctl_dir,
516 #define param_set_min_max(name, type, which_strtol, min, max) \
517 static int param_set_##name(const char *val, struct kernel_param *kp) \
520 __typeof__(type) num = which_strtol(val, &endp, 0); \
521 if (endp == val || *endp || num < (min) || num > (max)) \
523 *((type *) kp->arg) = num; \
527 static inline int is_callback(
u32 proc)
539 static int lockd_authenticate(
struct svc_rqst *rqstp)
547 if (is_callback(rqstp->
rq_proc)) {
561 nlm_grace_period_min, nlm_grace_period_max)
563 nlm_timeout_min, nlm_timeout_max)
570 &nlm_grace_period, 0644);
580 static
int lockd_init_net(
struct net *net)
590 static void lockd_exit_net(
struct net *net)
595 .init = lockd_init_net,
596 .exit = lockd_exit_net,
606 static int __init init_nlm(
void)
613 if (nlm_sysctl_table ==
NULL)
629 static void __exit exit_nlm(
void)
657 #ifdef CONFIG_LOCKD_V4
666 [1] = &nlmsvc_version1,
667 [3] = &nlmsvc_version3,
668 #ifdef CONFIG_LOCKD_V4
669 [4] = &nlmsvc_version4,
673 static struct svc_stat nlmsvc_stats;
675 #define NLM_NRVERS ARRAY_SIZE(nlmsvc_version)
679 .pg_vers = nlmsvc_version,
682 .pg_stats = &nlmsvc_stats,
683 .pg_authenticate = &lockd_authenticate