--- linux-2.4.21/fs/lockd/svc.c.orig 2003-08-21 22:01:41.000000000 -0400 +++ linux-2.4.21/fs/lockd/svc.c 2003-08-22 10:34:57.000000000 -0400 @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -51,19 +52,30 @@ static DECLARE_MUTEX_LOCKED(lockd_start) static DECLARE_WAIT_QUEUE_HEAD(lockd_exit); /* - * Currently the following can be set only at insmod time. - * Ideally, they would be accessible through the sysctl interface. + * These can be set at insmod time (useful for NFS as root filesystem), + * and also changed through the sysctl interface. -- Jamie Lokier, Aug 2003 */ -unsigned long nlm_grace_period; -unsigned long nlm_timeout = LOCKD_DFLT_TIMEO; -unsigned long nlm_udpport, nlm_tcpport; +static unsigned long nlm_grace_period; +static unsigned long nlm_timeout = LOCKD_DFLT_TIMEO; +static int nlm_udpport, nlm_tcpport; + +/* + * Constants needed for the sysctl interface. + */ +static const unsigned long nlm_grace_period_min = 0; +static const unsigned long nlm_grace_period_max = 240; +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; + +static struct ctl_table_header * nlm_sysctl_table; static unsigned long set_grace_period(void) { unsigned long grace_period; /* Note: nlm_timeout should always be nonzero */ - if (nlm_grace_period) + if (nlm_grace_period && nlm_timeout > 0) grace_period = ((nlm_grace_period + nlm_timeout - 1) / nlm_timeout) * nlm_timeout * HZ; else @@ -314,8 +326,76 @@ out: up(&nlmsvc_sema); } -#ifdef MODULE -/* New module support in 2.1.18 */ +/* + * Sysctl parameters (same as module parameters, different interface). + */ + +/* Something that isn't CTL_ANY, CTL_NONE or a value that may clash. */ +#define CTL_UNNUMBERED -2 + +static ctl_table nlm_sysctls[] = { + { + .ctl_name = CTL_UNNUMBERED, + .procname = "nlm_grace_period", + .data = &nlm_grace_period, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = &proc_doulongvec_minmax, + .extra1 = (unsigned long *) &nlm_grace_period_min, + .extra2 = (unsigned long *) &nlm_grace_period_max, + }, + { + .ctl_name = CTL_UNNUMBERED, + .procname = "nlm_timeout", + .data = &nlm_timeout, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = &proc_doulongvec_minmax, + .extra1 = (unsigned long *) &nlm_timeout_min, + .extra2 = (unsigned long *) &nlm_timeout_max, + }, + { + .ctl_name = CTL_UNNUMBERED, + .procname = "nlm_udpport", + .data = &nlm_udpport, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = &proc_dointvec_minmax, + .extra1 = (int *) &nlm_port_min, + .extra2 = (int *) &nlm_port_max, + }, + { + .ctl_name = CTL_UNNUMBERED, + .procname = "nlm_tcpport", + .data = &nlm_tcpport, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = &proc_dointvec_minmax, + .extra1 = (int *) &nlm_port_min, + .extra2 = (int *) &nlm_port_max, + }, + { .ctl_name = 0 } +}; + +static ctl_table nlm_sysctl_dir[] = { + { + .ctl_name = CTL_UNNUMBERED, + .procname = "nfs", + .mode = 0555, + .child = nlm_sysctls, + }, + { .ctl_name = 0 } +}; + +static ctl_table nlm_sysctl_root[] = { + { + .ctl_name = CTL_FS, + .procname = "fs", + .mode = 0555, + .child = nlm_sysctl_dir, + }, + { .ctl_name = 0 } +}; MODULE_AUTHOR("Olaf Kirch "); MODULE_DESCRIPTION("NFS file locking service version " LOCKD_VERSION "."); @@ -325,41 +405,26 @@ MODULE_PARM(nlm_timeout, "3-20l"); MODULE_PARM(nlm_udpport, "0-65535l"); MODULE_PARM(nlm_tcpport, "0-65535l"); -int -init_module(void) -{ - /* Init the static variables */ - init_MUTEX(&nlmsvc_sema); - nlmsvc_users = 0; - nlmsvc_pid = 0; - return 0; -} -void -cleanup_module(void) -{ - /* FIXME: delete all NLM clients */ - nlm_shutdown_hosts(); -} -#else -/* not a module, so process bootargs - * lockd.udpport and lockd.tcpport +/* + * Initialising and terminating the module. */ -static int __init udpport_set(char *str) +static int __init init_nlm(void) { - nlm_udpport = simple_strtoul(str, NULL, 0); - return 1; + nlm_sysctl_table = register_sysctl_table(nlm_sysctl_root, 0); + return nlm_sysctl_table ? 0 : -ENOMEM; } -static int __init tcpport_set(char *str) + +static void __exit exit_nlm(void) { - nlm_tcpport = simple_strtoul(str, NULL, 0); - return 1; + /* FIXME: delete all NLM clients */ + nlm_shutdown_hosts(); + unregister_sysctl_table(nlm_sysctl_table); } -__setup("lockd.udpport=", udpport_set); -__setup("lockd.tcpport=", tcpport_set); -#endif +module_init(init_nlm); +module_exit(exit_nlm); /* * Define NLM program and procedures