[klibc] [klibc:master] nfsmount: support nfsvers= and vers= options

klibc-bot for Baptiste Jonglez baptiste.jonglez at imag.fr
Fri Jan 18 08:42:05 PST 2019


Commit-ID:  c4b811a1e4647224ddc717fac59900d16d0e9d4d
Gitweb:     http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=c4b811a1e4647224ddc717fac59900d16d0e9d4d
Author:     Baptiste Jonglez <baptiste.jonglez at imag.fr>
AuthorDate: Thu, 14 Sep 2017 09:22:21 -0700
Committer:  Ben Hutchings <ben at decadent.org.uk>
CommitDate: Wed, 2 Jan 2019 03:08:04 +0000

[klibc] nfsmount: support nfsvers= and vers= options

The standard mount option nowadays to specify NFS version is "nfsvers", as
documented in nfs(5) on modern Linux systems.  Up to now, nfsmount only
supported the old "v2" or "v3" boolean options.

Extend option parsing to support both "nfsvers=X" and "vers=X", with X
being equal to either 2 or 3 (nfsmount does not support NFSv4 at present).
If both the new option "nfsvers=X" and old option "vX" are passed, the
version specified by "nfsvers" takes precedence.

Tested with initramfs-tools on Debian stretch, it can now successfully
mount the root on NFS using nfsmount, with the following kernel command
line:

    root=/dev/nfs nfsroot=server:path,nfsvers=3

Without this patch, such a command line would cause Debian's initrd to
loop with the following error message:

  Begin: Retrying nfs mount ... nfsmount: bad option 'nfsvers'

Signed-off-by: Baptiste Jonglez <baptiste.jonglez at imag.fr>
Link: https://www.zytor.com/pipermail/klibc/2017-September/003959.html
Signed-off-by: Ben Hutchings <ben at decadent.org.uk>

---
 usr/kinit/nfsmount/main.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/usr/kinit/nfsmount/main.c b/usr/kinit/nfsmount/main.c
index 36b29a5..cca9e4e 100644
--- a/usr/kinit/nfsmount/main.c
+++ b/usr/kinit/nfsmount/main.c
@@ -36,12 +36,15 @@ static struct nfs_mount_data mount_data = {
 };
 
 int nfs_port;
+int nfs_version;
 
 static struct int_opts {
 	char *name;
 	int *val;
 } int_opts[] = {
 	{"port",	&nfs_port},
+	{"nfsvers",	&nfs_version},
+	{"vers",	&nfs_version},
 	{"rsize",	&mount_data.rsize},
 	{"wsize",	&mount_data.wsize},
 	{"timeo",	&mount_data.timeo},
@@ -129,6 +132,22 @@ static void parse_opts(char *opts)
 			}
 		}
 	}
+	/* If new-style options "nfsvers=" or "vers=" are passed, override
+	   old "v2" and "v3" options */
+	if (nfs_version != 0) {
+		switch (nfs_version) {
+		case 2:
+			mount_data.flags &= ~NFS_MOUNT_VER3;
+			break;
+		case 3:
+			mount_data.flags |= NFS_MOUNT_VER3;
+			break;
+		default:
+			fprintf(stderr, "%s: bad NFS version '%d'\n",
+				progname, nfs_version);
+			longjmp(abort_buf, 1);
+		}
+	}
 }
 
 static uint32_t parse_addr(const char *ip)


More information about the klibc mailing list