Blame SOURCES/nfs-utils-1.3.0-mount-default-v42.patch

fc3648
diff --git a/configure.ac b/configure.ac
fc3648
index 56f7f3e..802fd58 100644
fc3648
--- a/configure.ac
fc3648
+++ b/configure.ac
fc3648
@@ -172,10 +172,12 @@ AC_ARG_ENABLE(ipv6,
fc3648
 if test "$enable_mount" = yes; then
fc3648
 	AC_ARG_ENABLE(mountconfig,
fc3648
 	[AC_HELP_STRING([--enable-mountconfig],
fc3648
-                        [enable mount to use a configuration file])],
fc3648
+        [enable mount to use a configuration file @<:@default=yes@:>@])],
fc3648
 	mountconfig=$enableval,
fc3648
-	mountconfig=no)
fc3648
-	if test "$enable_mountconfig" = yes; then
fc3648
+	mountconfig=yes)
fc3648
+	if test "$enable_mountconfig" = no; then
fc3648
+		enable_mountconfig=
fc3648
+	else
fc3648
 		AC_DEFINE(MOUNT_CONFIG, 1, 
fc3648
 			[Define this if you want mount to read a configuration file])
fc3648
 		AC_ARG_WITH(mountfile,
fc3648
@@ -187,8 +189,6 @@ if test "$enable_mount" = yes; then
fc3648
 		AC_SUBST(mountfile)
fc3648
 		AC_DEFINE_UNQUOTED(MOUNTOPTS_CONFFILE, "$mountfile", 
fc3648
 			[This defines the location of the NFS mount configuration file])
fc3648
-	else
fc3648
-		enable_mountconfig=
fc3648
 	fi
fc3648
 	AC_SUBST(enable_mountconfig)
fc3648
 	AM_CONDITIONAL(MOUNT_CONFIG, [test "$enable_mountconfig" = "yes"])
fc3648
diff --git a/utils/mount/configfile.c b/utils/mount/configfile.c
fc3648
index 39d3741..0a4cc04 100644
fc3648
--- a/utils/mount/configfile.c
fc3648
+++ b/utils/mount/configfile.c
fc3648
@@ -228,37 +228,8 @@ void free_all(void)
fc3648
 		free(entry);
fc3648
 	}
fc3648
 }
fc3648
-static char *versions[] = {"v2", "v3", "v4", "vers", "nfsvers", NULL};
fc3648
-static int 
fc3648
-check_vers(char *mopt, char *field)
fc3648
-{
fc3648
-	int i, found=0;
fc3648
-
fc3648
-	/*
fc3648
-	 * First check to see if the config setting is one 
fc3648
-	 * of the many version settings
fc3648
-	 */
fc3648
-	for (i=0; versions[i]; i++) { 
fc3648
-		if (strcasestr(field, versions[i]) != NULL) {
fc3648
-			found++;
fc3648
-			break;
fc3648
-		}
fc3648
-	}
fc3648
-	if (!found)
fc3648
-		return 0;
fc3648
-	/*
fc3648
-	 * It appears the version is being set, now see
fc3648
-	 * if the version appears on the command 
fc3648
-	 */
fc3648
-	for (i=0; versions[i]; i++)  {
fc3648
-		if (strcasestr(mopt, versions[i]) != NULL)
fc3648
-			return 1;
fc3648
-	}
fc3648
-
fc3648
-	return 0;
fc3648
-}
fc3648
 
fc3648
-unsigned long config_default_vers;
fc3648
+struct nfs_version config_default_vers;
fc3648
 unsigned long config_default_proto;
fc3648
 extern sa_family_t config_default_family;
fc3648
 
fc3648
@@ -331,11 +302,6 @@ conf_parse_mntopts(char *section, char *arg, char *opts)
fc3648
 		snprintf(buf, BUFSIZ, "%s=", node->field);
fc3648
 		if (opts && strcasestr(opts, buf) != NULL)
fc3648
 			continue;
fc3648
-		/* 
fc3648
-		 * Protocol verions can be set in a number of ways
fc3648
-		 */
fc3648
-		if (opts && check_vers(opts, node->field))
fc3648
-			continue;
fc3648
 
fc3648
 		if (lookup_entry(node->field) != NULL)
fc3648
 			continue;
fc3648
diff --git a/utils/mount/network.c b/utils/mount/network.c
fc3648
index 515249b..088caa1 100644
fc3648
--- a/utils/mount/network.c
fc3648
+++ b/utils/mount/network.c
fc3648
@@ -92,9 +92,6 @@ static const char *nfs_version_opttbl[] = {
fc3648
 	"v4",
fc3648
 	"vers",
fc3648
 	"nfsvers",
fc3648
-	"v4.0",
fc3648
-	"v4.1",
fc3648
-	"v4.2",
fc3648
 	NULL,
fc3648
 };
fc3648
 
fc3648
@@ -1249,71 +1246,69 @@ nfs_nfs_program(struct mount_options *options, unsigned long *program)
fc3648
  * or FALSE if the option was specified with an invalid value.
fc3648
  */
fc3648
 int
fc3648
-nfs_nfs_version(struct mount_options *options, unsigned long *version)
fc3648
+nfs_nfs_version(struct mount_options *options, struct nfs_version *version)
fc3648
 {
fc3648
-	long tmp;
fc3648
+	char *version_key, *version_val, *cptr;
fc3648
+	int i, found = 0;
fc3648
 
fc3648
-	switch (po_rightmost(options, nfs_version_opttbl)) {
fc3648
-	case 0:	/* v2 */
fc3648
-		*version = 2;
fc3648
-		return 1;
fc3648
-	case 1: /* v3 */
fc3648
-		*version = 3;
fc3648
-		return 1;
fc3648
-	case 2: /* v4 */
fc3648
-		*version = 4;
fc3648
-		return 1;
fc3648
-	case 3:	/* vers */
fc3648
-		switch (po_get_numeric(options, "vers", &tmp)) {
fc3648
-		case PO_FOUND:
fc3648
-			if (tmp >= 2 && tmp <= 4) {
fc3648
-				*version = tmp;
fc3648
-				return 1;
fc3648
-			}
fc3648
-			nfs_error(_("%s: parsing error on 'vers=' option\n"),
fc3648
-					progname);
fc3648
-			return 0;
fc3648
-		case PO_NOT_FOUND:
fc3648
-			nfs_error(_("%s: parsing error on 'vers=' option\n"),
fc3648
-					progname);
fc3648
-			return 0;
fc3648
-		case PO_BAD_VALUE:
fc3648
-			nfs_error(_("%s: invalid value for 'vers=' option"),
fc3648
-					progname);
fc3648
-			return 0;
fc3648
-		}
fc3648
-	case 4: /* nfsvers */
fc3648
-		switch (po_get_numeric(options, "nfsvers", &tmp)) {
fc3648
-		case PO_FOUND:
fc3648
-			if (tmp >= 2 && tmp <= 4) {
fc3648
-				*version = tmp;
fc3648
-				return 1;
fc3648
-			}
fc3648
-			nfs_error(_("%s: parsing error on 'nfsvers=' option\n"),
fc3648
-					progname);
fc3648
-			return 0;
fc3648
-		case PO_NOT_FOUND:
fc3648
-			nfs_error(_("%s: parsing error on 'nfsvers=' option\n"),
fc3648
-					progname);
fc3648
-			return 0;
fc3648
-		case PO_BAD_VALUE:
fc3648
-			nfs_error(_("%s: invalid value for 'nfsvers=' option"),
fc3648
-					progname);
fc3648
-			return 0;
fc3648
+	version->v_mode = V_DEFAULT;
fc3648
+
fc3648
+	for (i = 0; nfs_version_opttbl[i]; i++) {
fc3648
+		if (po_contains_prefix(options, nfs_version_opttbl[i],
fc3648
+								&version_key) == PO_FOUND) {
fc3648
+			found++;
fc3648
+			break;
fc3648
 		}
fc3648
-	case 5: /* v4.0 */
fc3648
-	case 6: /* v4.1 */
fc3648
-	case 7: /* v4.2 */
fc3648
-		*version = 4;
fc3648
+	}
fc3648
+
fc3648
+	if (!found)
fc3648
 		return 1;
fc3648
+
fc3648
+	if (i <= 2 ) {
fc3648
+		/* v2, v3, v4 */
fc3648
+		version_val = version_key + 1;
fc3648
+		version->v_mode = V_SPECIFIC;
fc3648
+	} else if (i > 2 ) {
fc3648
+		/* vers=, nfsvers= */
fc3648
+		version_val = po_get(options, version_key);
fc3648
 	}
fc3648
 
fc3648
-	/*
fc3648
-	 * NFS version wasn't specified.  The pmap version value
fc3648
-	 * will be filled in later by an rpcbind query in this case.
fc3648
-	 */
fc3648
-	*version = 0;
fc3648
+	if (!version_val)
fc3648
+		goto ret_error;
fc3648
+
fc3648
+	if (!(version->major = strtol(version_val, &cptr, 10)))
fc3648
+		goto ret_error;
fc3648
+
fc3648
+	if (version->major < 4)
fc3648
+		version->v_mode = V_SPECIFIC;
fc3648
+
fc3648
+	if (*cptr == '.') {
fc3648
+		version_val = ++cptr;
fc3648
+		if (!(version->minor = strtol(version_val, &cptr, 10)) && cptr == version_val)
fc3648
+			goto ret_error;
fc3648
+		version->v_mode = V_SPECIFIC;
fc3648
+	} else if (version->major > 3 && *cptr == '\0')
fc3648
+		version->v_mode = V_GENERAL;
fc3648
+
fc3648
+	if (*cptr != '\0')
fc3648
+		goto ret_error;
fc3648
+
fc3648
 	return 1;
fc3648
+
fc3648
+ret_error:
fc3648
+	if (i <= 2 ) {
fc3648
+		nfs_error(_("%s: parsing error on 'v' option"),
fc3648
+			progname);
fc3648
+	} else if (i == 3 ) {
fc3648
+		nfs_error(_("%s: parsing error on 'vers=' option"),
fc3648
+			progname);
fc3648
+	} else if (i == 4) {
fc3648
+		nfs_error(_("%s: parsing error on 'nfsvers=' option"),
fc3648
+			progname);
fc3648
+	}
fc3648
+	version->v_mode = V_PARSE_ERR;
fc3648
+	errno = EINVAL;
fc3648
+	return 0;
fc3648
 }
fc3648
 
fc3648
 /*
fc3648
@@ -1632,10 +1627,13 @@ out_err:
fc3648
 int nfs_options2pmap(struct mount_options *options,
fc3648
 		     struct pmap *nfs_pmap, struct pmap *mnt_pmap)
fc3648
 {
fc3648
+	struct nfs_version version;
fc3648
+
fc3648
 	if (!nfs_nfs_program(options, &nfs_pmap->pm_prog))
fc3648
 		return 0;
fc3648
-	if (!nfs_nfs_version(options, &nfs_pmap->pm_vers))
fc3648
+	if (!nfs_nfs_version(options, &version))
fc3648
 		return 0;
fc3648
+	nfs_pmap->pm_vers = version.major;
fc3648
 	if (!nfs_nfs_protocol(options, &nfs_pmap->pm_prot))
fc3648
 		return 0;
fc3648
 	if (!nfs_nfs_port(options, &nfs_pmap->pm_port))
fc3648
diff --git a/utils/mount/network.h b/utils/mount/network.h
fc3648
index d7636d7..9cc5dec 100644
fc3648
--- a/utils/mount/network.h
fc3648
+++ b/utils/mount/network.h
fc3648
@@ -57,9 +57,22 @@ int clnt_ping(struct sockaddr_in *, const unsigned long,
fc3648
 
fc3648
 struct mount_options;
fc3648
 
fc3648
+enum {
fc3648
+	V_DEFAULT = 0,
fc3648
+	V_GENERAL,
fc3648
+	V_SPECIFIC,
fc3648
+	V_PARSE_ERR,
fc3648
+};
fc3648
+
fc3648
+struct nfs_version {
fc3648
+	unsigned long major;
fc3648
+	unsigned long minor;
fc3648
+	int v_mode;
fc3648
+};
fc3648
+
fc3648
 int nfs_nfs_proto_family(struct mount_options *options, sa_family_t *family);
fc3648
 int nfs_mount_proto_family(struct mount_options *options, sa_family_t *family);
fc3648
-int nfs_nfs_version(struct mount_options *options, unsigned long *version);
fc3648
+int nfs_nfs_version(struct mount_options *options, struct nfs_version *version);
fc3648
 int  nfs_nfs_protocol(struct mount_options *options, unsigned long *protocol);
fc3648
 
fc3648
 int nfs_options2pmap(struct mount_options *,
fc3648
diff --git a/utils/mount/nfsumount.c b/utils/mount/nfsumount.c
fc3648
index 3538d88..de284f2 100644
fc3648
--- a/utils/mount/nfsumount.c
fc3648
+++ b/utils/mount/nfsumount.c
fc3648
@@ -179,10 +179,10 @@ static int nfs_umount_is_vers4(const struct mntentchn *mc)
fc3648
 
fc3648
 		options = po_split(pmc->m.mnt_opts);
fc3648
 		if (options != NULL) {
fc3648
-			unsigned long version;
fc3648
+			struct nfs_version version;
fc3648
 			int rc = nfs_nfs_version(options, &version);
fc3648
 			po_destroy(options);
fc3648
-			if (rc && version == 4)
fc3648
+			if (rc && version.major == 4)
fc3648
 				goto out_nfs4;
fc3648
 		}
fc3648
 
fc3648
diff --git a/utils/mount/parse_opt.c b/utils/mount/parse_opt.c
fc3648
index 75a0daa..7ba61c4 100644
fc3648
--- a/utils/mount/parse_opt.c
fc3648
+++ b/utils/mount/parse_opt.c
fc3648
@@ -391,7 +391,7 @@ po_return_t po_append(struct mount_options *options, char *str)
fc3648
 }
fc3648
 
fc3648
 /**
fc3648
- * po_contains - check for presense of an option in a group
fc3648
+ * po_contains - check for presence of an option in a group
fc3648
  * @options: pointer to mount options
fc3648
  * @keyword: pointer to a C string containing option keyword for which to search
fc3648
  *
fc3648
@@ -410,6 +410,30 @@ po_found_t po_contains(struct mount_options *options, char *keyword)
fc3648
 }
fc3648
 
fc3648
 /**
fc3648
+ * po_contains_prefix - check for presence of an option matching a prefix
fc3648
+ * @options: pointer to mount options
fc3648
+ * @prefix: pointer to prefix to match against a keyword
fc3648
+ * @keyword: pointer to a C string containing the option keyword if found
fc3648
+ *
fc3648
+ * On success, *keyword contains the pointer of the matching option's keyword.
fc3648
+ */
fc3648
+po_found_t po_contains_prefix(struct mount_options *options,
fc3648
+								const char *prefix, char **keyword)
fc3648
+{
fc3648
+	struct mount_option *option;
fc3648
+
fc3648
+	if (options && prefix) {
fc3648
+		for (option = options->head; option; option = option->next)
fc3648
+			if (strncmp(option->keyword, prefix, strlen(prefix)) == 0) {
fc3648
+				*keyword = option->keyword;
fc3648
+				return PO_FOUND;
fc3648
+			}
fc3648
+	}
fc3648
+
fc3648
+	return PO_NOT_FOUND;
fc3648
+}
fc3648
+
fc3648
+/**
fc3648
  * po_get - return the value of the rightmost instance of an option
fc3648
  * @options: pointer to mount options
fc3648
  * @keyword: pointer to a C string containing option keyword for which to search
fc3648
diff --git a/utils/mount/parse_opt.h b/utils/mount/parse_opt.h
fc3648
index 5037207..0745e0f 100644
fc3648
--- a/utils/mount/parse_opt.h
fc3648
+++ b/utils/mount/parse_opt.h
fc3648
@@ -45,6 +45,8 @@ po_return_t		po_join(struct mount_options *, char **);
fc3648
 
fc3648
 po_return_t		po_append(struct mount_options *, char *);
fc3648
 po_found_t		po_contains(struct mount_options *, char *);
fc3648
+po_found_t		po_contains_prefix(struct mount_options *options,
fc3648
+						const char *prefix, char **keyword);
fc3648
 char *			po_get(struct mount_options *, char *);
fc3648
 po_found_t		po_get_numeric(struct mount_options *,
fc3648
 					char *, long *);
fc3648
diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c
fc3648
index 5d80ed7..207a476 100644
fc3648
--- a/utils/mount/stropts.c
fc3648
+++ b/utils/mount/stropts.c
fc3648
@@ -88,30 +88,50 @@ struct nfsmount_info {
fc3648
 	struct mount_options	*options;	/* parsed mount options */
fc3648
 	char			**extra_opts;	/* string for /etc/mtab */
fc3648
 
fc3648
-	unsigned long		version;	/* NFS version */
fc3648
+	struct nfs_version	version;	/* NFS version */
fc3648
 	int			flags,		/* MS_ flags */
fc3648
 				fake,		/* actually do the mount? */
fc3648
 				child;		/* forked bg child? */
fc3648
 };
fc3648
 
fc3648
-#ifdef MOUNT_CONFIG
fc3648
-static void nfs_default_version(struct nfsmount_info *mi);
fc3648
 
fc3648
 static void nfs_default_version(struct nfsmount_info *mi)
fc3648
 {
fc3648
-	extern unsigned long config_default_vers;
fc3648
+#ifdef MOUNT_CONFIG
fc3648
+	extern struct nfs_version config_default_vers;
fc3648
 	/*
fc3648
 	 * Use the default value set in the config file when
fc3648
 	 * the version has not been explicitly set.
fc3648
 	 */
fc3648
-	if (mi->version == 0 && config_default_vers) {
fc3648
-		if (config_default_vers < 4)
fc3648
-			mi->version = config_default_vers;
fc3648
+	if (config_default_vers.v_mode == V_PARSE_ERR) {
fc3648
+		mi->version.v_mode = V_PARSE_ERR;
fc3648
+		return;
fc3648
 	}
fc3648
-}
fc3648
-#else
fc3648
-inline void nfs_default_version(__attribute__ ((unused)) struct nfsmount_info *mi) {}
fc3648
+
fc3648
+	if (mi->version.v_mode == V_GENERAL &&
fc3648
+		config_default_vers.v_mode == V_DEFAULT) {
fc3648
+		mi->version.v_mode = V_SPECIFIC;
fc3648
+		return;
fc3648
+	}
fc3648
+
fc3648
+	if (mi->version.v_mode == V_DEFAULT &&
fc3648
+		config_default_vers.v_mode != V_DEFAULT) {
fc3648
+		mi->version.major = config_default_vers.major;
fc3648
+		mi->version.minor = config_default_vers.minor;
fc3648
+		return;
fc3648
+	}
fc3648
+
fc3648
+	if (mi->version.v_mode == V_GENERAL &&
fc3648
+		config_default_vers.v_mode != V_DEFAULT) {
fc3648
+		if (mi->version.major == config_default_vers.major)
fc3648
+			mi->version.minor = config_default_vers.minor;
fc3648
+		return;
fc3648
+	}
fc3648
+
fc3648
 #endif /* MOUNT_CONFIG */
fc3648
+	mi->version.major = 4;
fc3648
+	mi->version.minor = 2;
fc3648
+}
fc3648
 
fc3648
 /*
fc3648
  * Obtain a retry timeout value based on the value of the "retry=" option.
fc3648
@@ -300,7 +320,7 @@ static int nfs_set_version(struct nfsmount_info *mi)
fc3648
 		return 0;
fc3648
 
fc3648
 	if (strncmp(mi->type, "nfs4", 4) == 0)
fc3648
-		mi->version = 4;
fc3648
+		mi->version.major = 4;
fc3648
 
fc3648
 	/*
fc3648
 	 * Before 2.6.32, the kernel NFS client didn't
fc3648
@@ -308,28 +328,44 @@ static int nfs_set_version(struct nfsmount_info *mi)
fc3648
 	 * 4 cannot be included when autonegotiating
fc3648
 	 * while running on those kernels.
fc3648
 	 */
fc3648
-	if (mi->version == 0 &&
fc3648
-	    linux_version_code() <= MAKE_VERSION(2, 6, 31))
fc3648
-		mi->version = 3;
fc3648
+	if (mi->version.v_mode == V_DEFAULT &&
fc3648
+	    linux_version_code() <= MAKE_VERSION(2, 6, 31)) {
fc3648
+		mi->version.major = 3;
fc3648
+		mi->version.v_mode = V_SPECIFIC;
fc3648
+	}
fc3648
 
fc3648
 	/*
fc3648
 	 * If we still don't know, check for version-specific
fc3648
 	 * mount options.
fc3648
 	 */
fc3648
-	if (mi->version == 0) {
fc3648
+	if (mi->version.v_mode == V_DEFAULT) {
fc3648
 		if (po_contains(mi->options, "mounthost") ||
fc3648
 		    po_contains(mi->options, "mountaddr") ||
fc3648
 		    po_contains(mi->options, "mountvers") ||
fc3648
-		    po_contains(mi->options, "mountproto"))
fc3648
-			mi->version = 3;
fc3648
+		    po_contains(mi->options, "mountproto")) {
fc3648
+			mi->version.major = 3;
fc3648
+			mi->version.v_mode = V_SPECIFIC;
fc3648
+		}
fc3648
 	}
fc3648
 
fc3648
 	/*
fc3648
 	 * If enabled, see if the default version was
fc3648
 	 * set in the config file
fc3648
 	 */
fc3648
-	nfs_default_version(mi);
fc3648
-	
fc3648
+	if (mi->version.v_mode != V_SPECIFIC) {
fc3648
+		nfs_default_version(mi);
fc3648
+		/*
fc3648
+		 * If the version was not specifically set, it will
fc3648
+		 * be set by autonegotiation later, so remove it now:
fc3648
+		 */
fc3648
+		po_remove_all(mi->options, "v4");
fc3648
+		po_remove_all(mi->options, "vers");
fc3648
+		po_remove_all(mi->options, "nfsvers");
fc3648
+	}
fc3648
+
fc3648
+	if (mi->version.v_mode == V_PARSE_ERR)
fc3648
+		return 0;
fc3648
+
fc3648
 	return 1;
fc3648
 }
fc3648
 
fc3648
@@ -693,6 +729,7 @@ static int nfs_do_mount_v4(struct nfsmount_info *mi,
fc3648
 {
fc3648
 	struct mount_options *options = po_dup(mi->options);
fc3648
 	int result = 0;
fc3648
+	char version_opt[16];
fc3648
 	char *extra_opts = NULL;
fc3648
 
fc3648
 	if (!options) {
fc3648
@@ -700,20 +737,24 @@ static int nfs_do_mount_v4(struct nfsmount_info *mi,
fc3648
 		return result;
fc3648
 	}
fc3648
 
fc3648
-	if (mi->version == 0) {
fc3648
-		if (po_contains(options, "mounthost") ||
fc3648
-			po_contains(options, "mountaddr") ||
fc3648
-			po_contains(options, "mountvers") ||
fc3648
-			po_contains(options, "mountproto")) {
fc3648
-		/*
fc3648
-		 * Since these mountd options are set assume version 3
fc3648
-		 * is wanted so error out with EPROTONOSUPPORT so the
fc3648
-		 * protocol negation starts with v3.
fc3648
-		 */
fc3648
-			errno = EPROTONOSUPPORT;
fc3648
-			goto out_fail;
fc3648
-		}
fc3648
-		if (po_append(options, "vers=4") == PO_FAILED) {
fc3648
+	if (po_contains(options, "mounthost") ||
fc3648
+		po_contains(options, "mountaddr") ||
fc3648
+		po_contains(options, "mountvers") ||
fc3648
+		po_contains(options, "mountproto")) {
fc3648
+	/*
fc3648
+	 * Since these mountd options are set assume version 3
fc3648
+	 * is wanted so error out with EPROTONOSUPPORT so the
fc3648
+	 * protocol negation starts with v3.
fc3648
+	 */
fc3648
+		errno = EPROTONOSUPPORT;
fc3648
+		goto out_fail;
fc3648
+	}
fc3648
+
fc3648
+	if (mi->version.v_mode != V_SPECIFIC) {
fc3648
+		snprintf(version_opt, sizeof(version_opt) - 1,
fc3648
+			"vers=%lu.%lu", mi->version.major, mi->version.minor);
fc3648
+
fc3648
+		if (po_append(options, version_opt) == PO_FAILED) {
fc3648
 			errno = EINVAL;
fc3648
 			goto out_fail;
fc3648
 		}
fc3648
@@ -801,14 +842,28 @@ static int nfs_autonegotiate(struct nfsmount_info *mi)
fc3648
 	int result;
fc3648
 
fc3648
 	result = nfs_try_mount_v4(mi);
fc3648
+check_result:
fc3648
 	if (result)
fc3648
 		return result;
fc3648
 
fc3648
-check_errno:
fc3648
 	switch (errno) {
fc3648
 	case EPROTONOSUPPORT:
fc3648
 		/* A clear indication that the server or our
fc3648
-		 * client does not support NFS version 4. */
fc3648
+		 * client does not support NFS version 4 and minor */
fc3648
+	case EINVAL:
fc3648
+		/* A less clear indication that our client
fc3648
+		 * does not support NFSv4 minor version. */
fc3648
+		if (mi->version.v_mode == V_GENERAL &&
fc3648
+			mi->version.minor == 0)
fc3648
+				return result;
fc3648
+		if (mi->version.v_mode != V_SPECIFIC) {
fc3648
+			if (mi->version.minor > 0) {
fc3648
+				mi->version.minor--;
fc3648
+				result = nfs_try_mount_v4(mi);
fc3648
+				goto check_result;
fc3648
+			}
fc3648
+		}
fc3648
+
fc3648
 		goto fall_back;
fc3648
 	case ENOENT:
fc3648
 		/* Legacy Linux servers don't export an NFS
fc3648
@@ -827,7 +882,7 @@ check_errno:
fc3648
 			/* v4 server seems to be registered now. */
fc3648
 			result = nfs_try_mount_v4(mi);
fc3648
 			if (result == 0 && errno != ECONNREFUSED)
fc3648
-				goto check_errno;
fc3648
+				goto check_result;
fc3648
 		}
fc3648
 		return result;
fc3648
 	default:
fc3648
@@ -848,19 +903,19 @@ static int nfs_try_mount(struct nfsmount_info *mi)
fc3648
 {
fc3648
 	int result = 0;
fc3648
 
fc3648
-	switch (mi->version) {
fc3648
-	case 0:
fc3648
-		result = nfs_autonegotiate(mi);
fc3648
-		break;
fc3648
-	case 2:
fc3648
-	case 3:
fc3648
-		result = nfs_try_mount_v3v2(mi, FALSE);
fc3648
-		break;
fc3648
-	case 4:
fc3648
-		result = nfs_try_mount_v4(mi);
fc3648
-		break;
fc3648
-	default:
fc3648
-		errno = EIO;
fc3648
+	switch (mi->version.major) {
fc3648
+		case 2:
fc3648
+		case 3:
fc3648
+			result = nfs_try_mount_v3v2(mi, FALSE);
fc3648
+			break;
fc3648
+		case 4:
fc3648
+			if (mi->version.v_mode != V_SPECIFIC)
fc3648
+				result = nfs_autonegotiate(mi);
fc3648
+			else
fc3648
+				result = nfs_try_mount_v4(mi);
fc3648
+			break;
fc3648
+		default:
fc3648
+			errno = EIO;
fc3648
 	}
fc3648
 
fc3648
 	return result;