8152f82
diff --git a/support/include/conffile.h b/support/include/conffile.h
8152f82
index 672020a..fe23ec2 100644
8152f82
--- a/support/include/conffile.h
8152f82
+++ b/support/include/conffile.h
8152f82
@@ -75,4 +75,11 @@ static inline void upper2lower(char *str)
8152f82
 	while ((c = tolower(*str)))
8152f82
 		*str++ = c;
8152f82
 }
8152f82
+
8152f82
+/*
8152f82
+ * Default Mount options
8152f82
+ */
8152f82
+extern unsigned long config_default_vers;
8152f82
+extern unsigned long config_default_proto;
8152f82
+
8152f82
 #endif				/* _CONFFILE_H_ */
8152f82
diff --git a/utils/mount/configfile.c b/utils/mount/configfile.c
8152f82
index e347b0e..28b722c 100644
8152f82
--- a/utils/mount/configfile.c
8152f82
+++ b/utils/mount/configfile.c
8152f82
@@ -20,13 +20,19 @@
8152f82
 #include <config.h>
8152f82
 #endif
8152f82
 #include <sys/types.h>
8152f82
+#include <sys/socket.h>
8152f82
+#include <netinet/in.h>
8152f82
 
8152f82
 #include <stdio.h>
8152f82
 #include <stdlib.h>
8152f82
 #include <string.h>
8152f82
 #include <ctype.h>
8152f82
+#include <errno.h>
8152f82
 
8152f82
 #include "xlog.h"
8152f82
+#include "mount.h"
8152f82
+#include "parse_opt.h"
8152f82
+#include "network.h"
8152f82
 #include "conffile.h"
8152f82
 
8152f82
 #define KBYTES(x)     ((x) * (1024))
8152f82
@@ -185,6 +191,63 @@ void free_all(void)
8152f82
 		free(entry);
8152f82
 	}
8152f82
 }
8152f82
+static char *versions[] = {"v2", "v3", "v4", "vers", "nfsvers", NULL};
8152f82
+int inline check_vers(char *mopt, char *field)
8152f82
+{
8152f82
+	int i;
8152f82
+
8152f82
+	if (strncmp("mountvers", field, strlen("mountvers")) != 0) {
8152f82
+		for (i=0; versions[i]; i++) 
8152f82
+			if (strcasestr(mopt, versions[i]) != NULL)
8152f82
+				return 1;
8152f82
+	}
8152f82
+	return 0;
8152f82
+}
8152f82
+
8152f82
+unsigned long config_default_vers;
8152f82
+unsigned long config_default_proto;
8152f82
+/*
8152f82
+ * Check to see if a default value is being set.
8152f82
+ * If so, set the appropriate global value which will 
8152f82
+ * be used as the initial value in the server negation.
8152f82
+ */
8152f82
+int inline default_value(char *mopt)
8152f82
+{
8152f82
+	struct mount_options *options = NULL;
8152f82
+	int dftlen = strlen("default");
8152f82
+	char *field;
8152f82
+
8152f82
+	if (strncasecmp(mopt, "default", dftlen) != 0)
8152f82
+		return 0;
8152f82
+
8152f82
+	field = mopt + dftlen;
8152f82
+	if (strncasecmp(field, "proto", strlen("proto")) == 0) {
8152f82
+		if ((options = po_split(field)) != NULL) {
8152f82
+			if (!nfs_nfs_protocol(options, &config_default_proto)) {
8152f82
+				xlog_warn("Unable to set default protocol : %s", 
8152f82
+					strerror(errno));
8152f82
+			}
8152f82
+		} else {
8152f82
+			xlog_warn("Unable to alloc memory for default protocol");
8152f82
+		}
8152f82
+	} else if (strncasecmp(field, "vers", strlen("vers")) == 0) {
8152f82
+		if ((options = po_split(field)) != NULL) {
8152f82
+			if (!nfs_nfs_version(options, &config_default_vers)) {
8152f82
+				xlog_warn("Unable to set default version: %s", 
8152f82
+					strerror(errno));
8152f82
+				
8152f82
+			}
8152f82
+		} else {
8152f82
+			xlog_warn("Unable to alloc memory for default version");
8152f82
+		}
8152f82
+	} else 
8152f82
+		xlog_warn("Invalid default setting: '%s'", mopt);
8152f82
+
8152f82
+	if (options)
8152f82
+		po_destroy(options);
8152f82
+
8152f82
+	return 1;
8152f82
+}
8152f82
 /*
8152f82
  * Parse the given section of the configuration 
8152f82
  * file to if there are any mount options set.
8152f82
@@ -207,6 +270,12 @@ conf_parse_mntopts(char *section, char *arg, char *opts)
8152f82
 		snprintf(buf, BUFSIZ, "%s=", node->field);
8152f82
 		if (opts && strcasestr(opts, buf) != NULL)
8152f82
 			continue;
8152f82
+		/* 
8152f82
+		 * Protocol verions can be set in a number of ways
8152f82
+		 */
8152f82
+		if (opts && check_vers(opts, node->field))
8152f82
+			continue;
8152f82
+
8152f82
 		if (lookup_entry(node->field) != NULL)
8152f82
 			continue;
8152f82
 		buf[0] = '\0';
8152f82
@@ -302,15 +371,19 @@ char *conf_get_mntopts(char *spec, char *mount_point,
8152f82
 		free_all();
8152f82
 		return mount_opts;
8152f82
 	}
8152f82
+
8152f82
 	if (mount_opts) {
8152f82
 		strcpy(config_opts, mount_opts);
8152f82
 		strcat(config_opts, ",");
8152f82
 	}
8152f82
 	SLIST_FOREACH(entry, &head, entries) {
8152f82
+		if (default_value(entry->opt))
8152f82
+			continue;
8152f82
 		strcat(config_opts, entry->opt);
8152f82
 		strcat(config_opts, ",");
8152f82
 	}
8152f82
-	*(strrchr(config_opts, ',')) = '\0';
8152f82
+	if ((ptr = strrchr(config_opts, ',')) != NULL)
8152f82
+		*ptr = '\0';
8152f82
 
8152f82
 	free_all();
8152f82
 	if (mount_opts)
8152f82
diff --git a/utils/mount/network.c b/utils/mount/network.c
8152f82
index bd621be..e651167 100644
8152f82
--- a/utils/mount/network.c
8152f82
+++ b/utils/mount/network.c
8152f82
@@ -50,6 +50,7 @@
8152f82
 #include "nfsrpc.h"
8152f82
 #include "parse_opt.h"
8152f82
 #include "network.h"
8152f82
+#include "conffile.h"
8152f82
 
8152f82
 #define PMAP_TIMEOUT	(10)
8152f82
 #define CONNECT_TIMEOUT	(20)
8152f82
@@ -609,10 +610,19 @@ static int nfs_probe_nfsport(const struct sockaddr *sap, const socklen_t salen,
8152f82
 	if (pmap->pm_vers && pmap->pm_prot && pmap->pm_port)
8152f82
 		return 1;
8152f82
 
8152f82
-	if (nfs_mount_data_version >= 4)
8152f82
+	if (nfs_mount_data_version >= 4) {
8152f82
+		const unsigned int *probe_proto = probe_tcp_first;
8152f82
+
8152f82
+		/*
8152f82
+		 * If the default proto has been set and 
8152f82
+		 * its not TCP, start with UDP
8152f82
+		 */
8152f82
+		if (config_default_proto && config_default_proto != IPPROTO_TCP)
8152f82
+			probe_proto =  probe_udp_first;
8152f82
+
8152f82
 		return nfs_probe_port(sap, salen, pmap,
8152f82
-					probe_nfs3_first, probe_tcp_first);
8152f82
-	else
8152f82
+					probe_nfs3_first, probe_proto);
8152f82
+	} else
8152f82
 		return nfs_probe_port(sap, salen, pmap,
8152f82
 					probe_nfs2_only, probe_udp_only);
8152f82
 }
8152f82
@@ -1261,7 +1271,7 @@ nfs_nfs_version(struct mount_options *options, unsigned long *version)
8152f82
  * Returns TRUE if @protocol contains a valid value for this option,
8152f82
  * or FALSE if the option was specified with an invalid value.
8152f82
  */
8152f82
-static int
8152f82
+int
8152f82
 nfs_nfs_protocol(struct mount_options *options, unsigned long *protocol)
8152f82
 {
8152f82
 	char *option;
8152f82
diff --git a/utils/mount/network.h b/utils/mount/network.h
8152f82
index 402e0a5..7eb89b0 100644
8152f82
--- a/utils/mount/network.h
8152f82
+++ b/utils/mount/network.h
8152f82
@@ -57,6 +57,8 @@ int clnt_ping(struct sockaddr_in *, const unsigned long,
8152f82
 struct mount_options;
8152f82
 
8152f82
 int nfs_nfs_version(struct mount_options *options, unsigned long *version);
8152f82
+int  nfs_nfs_protocol(struct mount_options *options, unsigned long *protocol);
8152f82
+
8152f82
 int nfs_options2pmap(struct mount_options *,
8152f82
 		      struct pmap *, struct pmap *);
8152f82
 
8152f82
diff --git a/utils/mount/nfsmount.conf b/utils/mount/nfsmount.conf
8152f82
index f9fcfcb..9b8ff4a 100644
8152f82
--- a/utils/mount/nfsmount.conf
8152f82
+++ b/utils/mount/nfsmount.conf
8152f82
@@ -24,14 +24,29 @@
8152f82
 # All reads and writes to the 'nfsserver.foo.com' server 
8152f82
 # will be done with 32k (32768 bytes) block sizes.
8152f82
 #
8152f82
-#[ NFSMount_Global_Options ]
8152f82
+[ NFSMount_Global_Options ]
8152f82
 # This statically named section defines global mount 
8152f82
 # options that can be applied on all NFS mount.
8152f82
 #
8152f82
-# Protocol Version [2,3]
8152f82
-# Nfsvers=3
8152f82
-# Network Transport [Udp,Tcp,Rdma]
8152f82
-# Proto=Tcp
8152f82
+# Protocol Version [2,3,4]
8152f82
+# This defines the default protocol version which will
8152f82
+# be used to start the negotiation with the server.
8152f82
+# Defaultvers=4
8152f82
+#
8152f82
+# Setting this option makes it mandatory the server supports the
8152f82
+# given version. The mount will fail if the given version is 
8152f82
+# not support by the server. 
8152f82
+# Nfsvers=4
8152f82
+#
8152f82
+# Network Protocol [udp,tcp,rdma] (Note: values are case sensitive)
8152f82
+# This defines the default network protocol which will
8152f82
+# be used to start the negotiation with the server.
8152f82
+# Defaultproto=tcp
8152f82
+#
8152f82
+# Setting this option makes it mandatory the server supports the
8152f82
+# given network protocol. The mount will fail if the given network
8152f82
+# protocol is not supported by the server.
8152f82
+# Proto=tcp
8152f82
 #
8152f82
 # The number of times a request will be retired before 
8152f82
 # generating a timeout 
8152f82
diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c
8152f82
index 069bdc1..ceefdb0 100644
8152f82
--- a/utils/mount/stropts.c
8152f82
+++ b/utils/mount/stropts.c
8152f82
@@ -45,6 +45,7 @@
8152f82
 #include "parse_opt.h"
8152f82
 #include "version.h"
8152f82
 #include "parse_dev.h"
8152f82
+#include "conffile.h"
8152f82
 
8152f82
 #ifndef NFS_PROGRAM
8152f82
 #define NFS_PROGRAM	(100003)
8152f82
@@ -283,6 +284,14 @@ static int nfs_validate_options(struct nfsmount_info *mi)
8152f82
 		if (option && strcmp(option, "rdma") == 0)
8152f82
 			mi->version = 3;
8152f82
 	}
8152f82
+	/*
8152f82
+	 * Use the default value set in the config file when
8152f82
+	 * the version has not been explicitly set.
8152f82
+	 */
8152f82
+	if (mi->version == 0 && config_default_vers) {
8152f82
+		if (config_default_vers < 4)
8152f82
+			mi->version = config_default_vers;
8152f82
+	}
8152f82
 
8152f82
 	if (!nfs_append_sloppy_option(mi->options))
8152f82
 		return 0;