[RFC] Making mount_nfs to attempt NFSv4 before NFSv3 and NFSv2?

From: Xin Li via freebsd-current <freebsd-current_at_freebsd.org>
Date: Mon, 03 Jan 2022 18:51:31 UTC
Hi,

Currently, mount_nfs will attempt to use NFSv3 and fallback to NFSv2. 
The manual page says:

      nfsv2   Use the NFS Version 2 protocol (the default is to try
              version 3 first then version 2).  Note that NFS version 2
              has a file size limit of 2 gigabytes.

And the code agrees, too:

%%%%%%%%
         if (trymntmode == V4) {
                 nfsvers = 4;
                 mntvers = 3; /* Workaround for GCC. */
         } else if (trymntmode == V2) {
                 nfsvers = 2;
                 mntvers = 1;
         } else {
                 nfsvers = 3;
                 mntvers = 3;
         }
%%%%%%%%

When trymntmode == ANY, which is the default, mount_nfs would attempt 
NFSv3, and if rpcb_getaddr() returned RPC_PROGVERSMISMATCH, it would try 
again with trymntmode = V2.

Nowadays, it seems that NFSv4 is becoming more and more popular.  If a 
server is providing only NFSv4 service, when mounting without -o nfsv4, 
the user would receive message like:

	RPCPROG_MNT: RPC:Timed out

A friend of mine who is using TrueNAS core hit this yesterday and his 
Linux client worked just fine.  It took me some time to figure out that 
the root cause.  It seems that modern Linux distributions have been 
using NFSv4 by default for some time.

So I think it makes sense to teach mount_nfs to attempt NFSv4, then 
NFSv3 and NFSv2.  However, this might be a POLA violation and we would 
like to know if there is any objections.

(I've attached a patch but I haven't actually tested it yet).

Cheers,