Bug 282481

Summary: Need to be able to specify NFS mounport and not use port mapper
Product: Base System Reporter: Ronald Minnich <rminnich>
Component: binAssignee: Rick Macklem <rmacklem>
Status: Closed FIXED    
Severity: Affects Many People CC: pat, rmacklem
Priority: --- Flags: rmacklem: mfc-stable14+
rmacklem: mfc-stable13-
Version: Unspecified   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
Add a mountport option to mount_nfs to avoid rpcbind none

Description Ronald Minnich 2024-11-02 04:07:53 UTC
GitHub.com/u-root/cpu is an implementation of the Plan 9 cpu command. In cpu, users connect from a local system to a remote system, but it is possible to use some or all of the local file system on the remote system. 

cpu is used by both ARM and Google, among others.

More information here: https://docs.google.com/presentation/d/12_mZR-tpjHNrq6xMEqXQMHPiQej4o3Mink-Rkapiw50/edit?usp=sharing

cpu clients work today on linux, Darwin, osx, and windows. 

cpud works only on Linux. 

We are getting cpud working on freebsd. 

To get this to work, however, it must be possible to use both the NFS3 mount and NFS3 server provided by the cpu command. 

The problem comes in when cpud tries to mount the NFS3 server provided by cpu.

Currently, freebsd mount assumes that all mount servers are registered with the port mapper, and uses SUNRPC calls to port 111 to locate and connect to mount servers. If no port mapper is running; the mount will fail. Even if a port mapper is running, there is no practical way for the cpu client to contact the port mapper on the system running cpud; we would not want it to, anyway, as the mount namespace provided by cpu should be private to the single session it is running with cpud*.

Linux allows us to specify the mount port of the mount server, bypassing the port mapper entirely. 

We would like to have this same ability on freebsd. One option might be as follows: add a mountport option to the set of options passed to mount_nfs.

mount -t nfs -o mountport=abcde,port=abcde,etc.etc 127.0.0.1:whatever /some/directory.

*While there do not seem to be private mount namespaces on freebsd at present, we hope there will be someday. Nevertheless, even without private namespaces, cpu/cpud would be very useful for small IoT devices.
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2024-11-02 04:16:14 UTC
*** Bug 282482 has been marked as a duplicate of this bug. ***
Comment 2 Ronald Minnich 2024-11-02 04:40:47 UTC
oops. Sorry. hit some kind of glitch.
Comment 3 Rick Macklem freebsd_committer freebsd_triage 2024-11-02 20:27:22 UTC
Created attachment 254886 [details]
Add a mountport option to mount_nfs to avoid rpcbind

This patch adds a new NFS mount option called
mountport that can be used to specify the port#
for the NFS server's Mount protocol (mountd).

If used with the port option (port=2049 unless
the NFS server is using a non-default port#,
mount_nfs(8) will not expect to find portmapper/rpcbind
running on the NFS server.

This patch is slightly different from the one Ron is testing,
but should behave the same way.
I will write of a man page patch and work towards having
both committed to main, etc.
Comment 4 Rick Macklem freebsd_committer freebsd_triage 2024-12-11 23:09:00 UTC
The patch has been committed to main.
Comment 5 commit-hook freebsd_committer freebsd_triage 2024-12-11 23:09:30 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=0e8a36a2ab1223ffb0cbdfd49383d8cf978cfa74

commit 0e8a36a2ab1223ffb0cbdfd49383d8cf978cfa74
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2024-12-11 23:07:05 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2024-12-11 23:07:05 +0000

    mount_nfs.c: Add an NFS mount option to set a port# for Mount

    Normally mount_nfs acquires the port# for the NFS server's
    Mount protocol (mountd(8)) via rpcbind/portmapper for
    NFSv3 mounts.

    This patch adds a new mount option, so that the mount
    command can specify the port# and avoid using rpcbind
    for NFSv3 mounts.

    The new option is called "mountport" since that is what Linux
    calls their mount option for the same semantics.

    PR:     282481
    Reviewed by:    delphij
    Tested by:      Ronald Minnich <rminnich@gmail.com>
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D47743

 sbin/mount_nfs/mount_nfs.c | 56 ++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 49 insertions(+), 7 deletions(-)
Comment 6 commit-hook freebsd_committer freebsd_triage 2024-12-25 01:46:59 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=400fcd1d4fc85212526e9f304e4e90b5668316be

commit 400fcd1d4fc85212526e9f304e4e90b5668316be
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2024-12-11 23:07:05 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2024-12-25 01:44:40 +0000

    mount_nfs.c: Add an NFS mount option to set a port# for Mount

    Normally mount_nfs acquires the port# for the NFS server's
    Mount protocol (mountd(8)) via rpcbind/portmapper for
    NFSv3 mounts.

    This patch adds a new mount option, so that the mount
    command can specify the port# and avoid using rpcbind
    for NFSv3 mounts.

    The new option is called "mountport" since that is what Linux
    calls their mount option for the same semantics.

    PR:     282481

    (cherry picked from commit 0e8a36a2ab1223ffb0cbdfd49383d8cf978cfa74)

 sbin/mount_nfs/mount_nfs.c | 56 ++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 49 insertions(+), 7 deletions(-)
Comment 7 Rick Macklem freebsd_committer freebsd_triage 2024-12-25 01:52:10 UTC
Patch has been committed and MFC'd.