Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 66575 - /etc/conf.d/nfs doesn't allow setting ports used by lockd/nlockmgr
Summary: /etc/conf.d/nfs doesn't allow setting ports used by lockd/nlockmgr
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: All Linux
: High normal
Assignee: SpanKY
URL:
Whiteboard:
Keywords:
: 124882 124889 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-10-06 15:32 UTC by Sven
Modified: 2006-03-03 18:02 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sven 2004-10-06 15:32:01 UTC
Hi,

since kernel 2.6 there's a neat way of setting the ports used by lockd/nlockmgr. /etc/conf.d/nfs could define two values:
  RPCLOCKD_UDPPORT=0
  RPCLOCKD_TCPPORT=0

where 0 is the default, which makes the kernel allocate a dynamic port. the values can eb set by simply using two sysctl-commands:

  sysctl -w fs.nfs.nlm_udpport=$RPCLOCKD_UDPPORT
  sysctl -w fs.nfs.nlm_tcpport=$RPCLOCKD_TCPPORT

This must be executed after loading the nfsd module (which is currently not done by any /etc/init.d/nfs-script, see Bug 64709) and before starting any servers.

Since these values don't exist until the nfsd-module it loaded, this cannot be done /etc/sysctl.conf. On the other hand, the other ports are also defined in /etc/conf.d/nfs, so why don't configure the lockd-ports there too.

Having static ports is very important for firewalled systems.


Reproducible: Always
Steps to Reproduce:
Comment 1 Sven 2004-10-06 15:39:35 UTC
Here's a patch, although it doesn't check for the kernel-version yet:

# diff -u nfs-5 /etc/init.d/nfs                                                                                                                                                      
--- nfs-5       2004-07-15 02:06:24.000000000 +0200
+++ /etc/init.d/nfs     2004-10-07 00:31:02.944810936 +0200
@@ -64,6 +64,11 @@
 }
 
 start() {
+       modprobe nfsd >/dev/null 2>&1
+
+       sysctl -q -w fs.nfs.nlm_udpport=$RPCLOCKD_UDP
+       sysctl -q -w fs.nfs.nlm_tcpport=$RPCLOCKD_TCP
+
        # This is the new "kernel 2.6 way" to handle the exports file
        if grep -q nfsd /proc/filesystems &>/dev/null; then
                if ! grep -q "nfsd /proc/fs/nfs" /proc/mounts &>/dev/null; then
Comment 2 Sven 2004-10-06 15:55:07 UTC
here's a much better test, that checks if the kernel has support for the sysctl-values:

# diff -u nfs-5 /etc/init.d/nfs                                                                                                                                                      
--- nfs-5       2004-07-15 02:06:24.000000000 +0200
+++ /etc/init.d/nfs     2004-10-07 00:48:08.467907728 +0200
@@ -63,7 +63,24 @@
        wait $1
 }
 
+set_lockd_port() {
+       local type="$1"
+       local port="$2"
+
+       if sysctl "fs.nfs.nlm_${type}port" >/dev/null 2>&1
+       then
+               ebegin "Setting lockd $type-port"
+               sysctl -q -w "fs.nfs.nlm_${type}port=$port"
+               eend $? "Your kernel doesn't support this"
+       fi
+}
+
 start() {
+       modprobe nfsd >/dev/null 2>&1
+
+       set_lockd_port udp "$RPCLOCKD_UDP"
+       set_lockd_port tcp "$RPCLOCKD_TCP"
+       
        # This is the new "kernel 2.6 way" to handle the exports file
        if grep -q nfsd /proc/filesystems &>/dev/null; then
                if ! grep -q "nfsd /proc/fs/nfs" /proc/mounts &>/dev/null; then
Comment 3 SpanKY gentoo-dev 2004-10-07 20:15:10 UTC
i dont understand why you dont put your nfs module into modules.autoload and then put those settings into your sysctl.conf
Comment 4 Sven 2004-10-08 02:18:28 UTC
@vapier: This is something that doesn't have to be done, but it's a great service for gentoo-admins. I also think, that there's no better place to this, than /etc/init.d/nfs: 
- /etc/init.d/local is started after /etc/init.d/nfs, and it the lockd has already been, the sysctl-stuff has no effect, and so /etc/conf.d/local.start is the wrong place
- /etc/sysctl.conf is used by /etc/init.d/bootmisc. That doesn't depend on /etc/init.d/modules, and therefor the nsfd-module isn't loaded, and so the sysctl-command in /etc/init.d/bootmisc will fail, since the setting aren't available yet, since the nfsd module hasn't been loaded yet
- with the ports set in /etc/init.d/nfs and changed ports in /etc/conf.d/nfs, /etc/init.d/nfs restart should also correctly set the port-numbers and they will even be used, by the just restarted lockd/nlockmgr.
Comment 5 SpanKY gentoo-dev 2004-10-08 05:54:40 UTC
bootmisc needs localmount which needs checkfs which needs modules

so if you have nfsd in your modules.autoload, everything will work correctly
Comment 6 Sven 2004-10-08 06:00:44 UTC
OK, i agree, but still, many users don't know that those sysctl-paramters exist, and it took me an hour googling, and having the ports in /etc/conf.d/nfs would be a thing, where an admin will find them within seconds ...
Comment 7 SpanKY gentoo-dev 2004-10-08 06:21:43 UTC
or, how about i add some comments to the top of the conf.d/nfs file explaining that if they wish to set the ports, they should make sure nfsd is built into the kernel/in modules.autoload and they should update /etc/sysctl.conf
Comment 8 Sven 2004-10-08 06:44:52 UTC
Oh well, put some hints in /etc/conf.d/nfs about sysctl.conf and modules.autoload.d and close this bug.
Admins who want to change the ports will look into /etc/conf.d/nfs and therefor find the hints, although this is the minimum of userfriendlyness ;-)
Comment 9 SpanKY gentoo-dev 2004-10-09 11:51:16 UTC
added not to conf.d file in cvs
Comment 10 SpanKY gentoo-dev 2006-03-03 17:21:47 UTC
*** Bug 124889 has been marked as a duplicate of this bug. ***
Comment 11 Tuan Van (RETIRED) gentoo-dev 2006-03-03 17:39:05 UTC
/etc/conf.d/nfs
# If you wish to set the port numbers for lockd,
# please see /etc/sysctl.conf
...

/etc/sysctl.conf
...
# TCP Port for lock manager
# fs.nfs.nlm_tcpport = 32768
# UDP Port for lock manager
# fs.nfs.nlm_udpport = 32768
above didn't mention anything about put nfsd in modules.autoload
Comment 12 SpanKY gentoo-dev 2006-03-03 17:51:58 UTC
*** Bug 124882 has been marked as a duplicate of this bug. ***
Comment 13 SpanKY gentoo-dev 2006-03-03 18:02:17 UTC
added a note even though that seems kind of obvious to me :P