1e5327b
diff --git a/utils/mount/parse_opt.c b/utils/mount/parse_opt.c
1e5327b
index 1dfee8a..f0918f7 100644
1e5327b
--- a/utils/mount/parse_opt.c
1e5327b
+++ b/utils/mount/parse_opt.c
1e5327b
@@ -101,6 +101,37 @@ fail:
1e5327b
 	return NULL;
1e5327b
 }
1e5327b
 
1e5327b
+static struct mount_option *option_dup(const struct mount_option *option)
1e5327b
+{
1e5327b
+	struct mount_option *new;
1e5327b
+
1e5327b
+	new = malloc(sizeof(*new));
1e5327b
+	if (!new)
1e5327b
+		return NULL;
1e5327b
+	
1e5327b
+	new->next = NULL;
1e5327b
+	new->prev = NULL;
1e5327b
+
1e5327b
+	new->keyword = strdup(option->keyword);
1e5327b
+	if (!new->keyword)
1e5327b
+		goto fail;
1e5327b
+
1e5327b
+	new->value = NULL;
1e5327b
+	if (option->value) {
1e5327b
+		new->value = strdup(option->value);
1e5327b
+		if (!new->value) {
1e5327b
+			free(new->keyword);
1e5327b
+			goto fail;
1e5327b
+		}
1e5327b
+	}
1e5327b
+
1e5327b
+	return new;
1e5327b
+
1e5327b
+fail:
1e5327b
+	free(new);
1e5327b
+	return NULL;
1e5327b
+}
1e5327b
+
1e5327b
 static void option_destroy(struct mount_option *option)
1e5327b
 {
1e5327b
 	free(option->keyword);
1e5327b
@@ -229,6 +260,40 @@ fail:
1e5327b
 }
1e5327b
 
1e5327b
 /**
1e5327b
+ * po_dup - duplicate an existing list of options
1e5327b
+ * @options: pointer to mount options
1e5327b
+ *
1e5327b
+ */
1e5327b
+struct mount_options *po_dup(struct mount_options *source)
1e5327b
+{
1e5327b
+	struct mount_options *target;
1e5327b
+	struct mount_option *current;
1e5327b
+
1e5327b
+	if (!source)
1e5327b
+		return NULL;
1e5327b
+
1e5327b
+	target = options_create();
1e5327b
+	if (options_empty(source) || target == NULL)
1e5327b
+		return target;
1e5327b
+
1e5327b
+	current = source->head;
1e5327b
+	while (target->count < source->count) {
1e5327b
+		struct mount_option *option;
1e5327b
+
1e5327b
+		option = option_dup(current);
1e5327b
+		if (!option) {
1e5327b
+			po_destroy(target);
1e5327b
+			return NULL;
1e5327b
+		}
1e5327b
+
1e5327b
+		options_tail_insert(target, option);
1e5327b
+		current = current->next;
1e5327b
+	}
1e5327b
+
1e5327b
+	return target;
1e5327b
+}
1e5327b
+
1e5327b
+/**
1e5327b
  * po_replace - replace mount options in one mount_options object with another
1e5327b
  * @target: pointer to previously instantiated object to replace
1e5327b
  * @source: pointer to object containing source mount options
1e5327b
diff --git a/utils/mount/parse_opt.h b/utils/mount/parse_opt.h
1e5327b
index f9243c3..2c0b5f4 100644
1e5327b
--- a/utils/mount/parse_opt.h
1e5327b
+++ b/utils/mount/parse_opt.h
1e5327b
@@ -38,6 +38,7 @@ typedef enum {
1e5327b
 struct mount_options;
1e5327b
 
1e5327b
 struct mount_options *	po_split(char *);
1e5327b
+struct mount_options *	po_dup(struct mount_options *);
1e5327b
 void			po_replace(struct mount_options *,
1e5327b
 				   struct mount_options *);
1e5327b
 po_return_t		po_join(struct mount_options *, char **);
1e5327b
diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c
1e5327b
index 3eb661e..069bdc1 100644
1e5327b
--- a/utils/mount/stropts.c
1e5327b
+++ b/utils/mount/stropts.c
1e5327b
@@ -80,6 +80,8 @@ struct nfsmount_info {
1e5327b
 				*node,		/* mounted-on dir */
1e5327b
 				*type;		/* "nfs" or "nfs4" */
1e5327b
 	char			*hostname;	/* server's hostname */
1e5327b
+	struct sockaddr_storage	address;	/* server's address */
1e5327b
+	socklen_t		salen;		/* size of server's address */
1e5327b
 
1e5327b
 	struct mount_options	*options;	/* parsed mount options */
1e5327b
 	char			**extra_opts;	/* string for /etc/mtab */
1e5327b
@@ -257,47 +259,35 @@ static int nfs_append_sloppy_option(struct mount_options *options)
1e5327b
 }
1e5327b
 
1e5327b
 /*
1e5327b
- * Set up mandatory NFS mount options.
1e5327b
+ * Set up mandatory non-version specific NFS mount options.
1e5327b
  *
1e5327b
  * Returns 1 if successful; otherwise zero.
1e5327b
  */
1e5327b
 static int nfs_validate_options(struct nfsmount_info *mi)
1e5327b
 {
1e5327b
-	struct sockaddr_storage dummy;
1e5327b
-	struct sockaddr *sap = (struct sockaddr *)&dummy;
1e5327b
-	socklen_t salen = sizeof(dummy);
1e5327b
+	struct sockaddr *sap = (struct sockaddr *)&mi->address;
1e5327b
 
1e5327b
 	if (!nfs_parse_devname(mi->spec, &mi->hostname, NULL))
1e5327b
 		return 0;
1e5327b
 
1e5327b
-	if (!nfs_name_to_address(mi->hostname, sap, &salen))
1e5327b
+	mi->salen = sizeof(mi->address);
1e5327b
+	if (!nfs_name_to_address(mi->hostname, sap, &mi->salen))
1e5327b
 		return 0;
1e5327b
 
1e5327b
 	if (!nfs_nfs_version(mi->options, &mi->version))
1e5327b
 		return 0;
1e5327b
 	if (strncmp(mi->type, "nfs4", 4) == 0)
1e5327b
 		mi->version = 4;
1e5327b
-
1e5327b
-	if (mi->version == 4) {
1e5327b
-		if (!nfs_append_clientaddr_option(sap, salen, mi->options))
1e5327b
-			return 0;
1e5327b
-	} else {
1e5327b
-		if (!nfs_fix_mounthost_option(mi->options))
1e5327b
-			return 0;
1e5327b
-		if (!mi->fake && !nfs_verify_lock_option(mi->options))
1e5327b
-			return 0;
1e5327b
+	else {
1e5327b
+		char *option = po_get(mi->options, "proto");
1e5327b
+		if (option && strcmp(option, "rdma") == 0)
1e5327b
+			mi->version = 3;
1e5327b
 	}
1e5327b
 
1e5327b
 	if (!nfs_append_sloppy_option(mi->options))
1e5327b
 		return 0;
1e5327b
 
1e5327b
-	if (!nfs_append_addr_option(sap, salen, mi->options))
1e5327b
-		return 0;
1e5327b
-
1e5327b
-	/*
1e5327b
-	 * Update option string to be recorded in /etc/mnttab
1e5327b
-	 */
1e5327b
-	if (po_join(mi->options, mi->extra_opts) == PO_FAILED)
1e5327b
+	if (!nfs_append_addr_option(sap, mi->salen, mi->options))
1e5327b
 		return 0;
1e5327b
 
1e5327b
 	return 1;
1e5327b
@@ -489,17 +479,12 @@ out:
1e5327b
  * Returns TRUE if successful, otherwise FALSE.
1e5327b
  * "errno" is set to reflect the individual error.
1e5327b
  */
1e5327b
-static int nfs_try_mount(struct nfsmount_info *mi)
1e5327b
+static int nfs_sys_mount(struct nfsmount_info *mi, struct mount_options *opts)
1e5327b
 {
1e5327b
 	char *options = NULL;
1e5327b
 	int result;
1e5327b
 
1e5327b
-	if (mi->version != 4) {
1e5327b
-		if (!nfs_rewrite_pmap_mount_options(mi->options))
1e5327b
-			return 0;
1e5327b
-	}
1e5327b
-
1e5327b
-	if (po_join(mi->options, &options) == PO_FAILED) {
1e5327b
+	if (po_join(opts, &options) == PO_FAILED) {
1e5327b
 		errno = EIO;
1e5327b
 		return 0;
1e5327b
 	}
1e5327b
@@ -522,6 +507,121 @@ static int nfs_try_mount(struct nfsmount_info *mi)
1e5327b
 }
1e5327b
 
1e5327b
 /*
1e5327b
+ * For "-t nfs vers=2" or "-t nfs vers=3" mounts.
1e5327b
+ */
1e5327b
+static int nfs_try_mount_v3v2(struct nfsmount_info *mi)
1e5327b
+{
1e5327b
+	struct mount_options *options = po_dup(mi->options);
1e5327b
+	int result = 0;
1e5327b
+
1e5327b
+	if (!options) {
1e5327b
+		errno = ENOMEM;
1e5327b
+		return result;
1e5327b
+	}
1e5327b
+
1e5327b
+	if (!nfs_fix_mounthost_option(options)) {
1e5327b
+		errno = EINVAL;
1e5327b
+		goto out_fail;
1e5327b
+	}
1e5327b
+	if (!mi->fake && !nfs_verify_lock_option(options)) {
1e5327b
+		errno = EINVAL;
1e5327b
+		goto out_fail;
1e5327b
+	}
1e5327b
+
1e5327b
+	/*
1e5327b
+	 * Options we negotiate below may be stale by the time this
1e5327b
+	 * file system is unmounted.  In order to force umount.nfs
1e5327b
+	 * to renegotiate with the server, only write the user-
1e5327b
+	 * specified options, and not negotiated options, to /etc/mtab.
1e5327b
+	 */
1e5327b
+	if (po_join(options, mi->extra_opts) == PO_FAILED) {
1e5327b
+		errno = ENOMEM;
1e5327b
+		goto out_fail;
1e5327b
+	}
1e5327b
+
1e5327b
+	if (!nfs_rewrite_pmap_mount_options(options))
1e5327b
+		goto out_fail;
1e5327b
+
1e5327b
+	result = nfs_sys_mount(mi, options);
1e5327b
+
1e5327b
+out_fail:
1e5327b
+	po_destroy(options);
1e5327b
+	return result;
1e5327b
+}
1e5327b
+
1e5327b
+/*
1e5327b
+ * For "-t nfs -o vers=4" or "-t nfs4" mounts.
1e5327b
+ */
1e5327b
+static int nfs_try_mount_v4(struct nfsmount_info *mi)
1e5327b
+{
1e5327b
+	struct sockaddr *sap = (struct sockaddr *)&mi->address;
1e5327b
+	struct mount_options *options = po_dup(mi->options);
1e5327b
+	int result = 0;
1e5327b
+
1e5327b
+	if (!options) {
1e5327b
+		errno = ENOMEM;
1e5327b
+		return result;
1e5327b
+	}
1e5327b
+
1e5327b
+	if (mi->version == 0) {
1e5327b
+		if (po_append(options, "vers=4") == PO_FAILED) {
1e5327b
+			errno = EINVAL;
1e5327b
+			goto out_fail;
1e5327b
+		}
1e5327b
+	}
1e5327b
+
1e5327b
+	if (!nfs_append_clientaddr_option(sap, mi->salen, options)) {
1e5327b
+		errno = EINVAL;
1e5327b
+		goto out_fail;
1e5327b
+	}
1e5327b
+	/*
1e5327b
+	 * Update option string to be recorded in /etc/mtab.
1e5327b
+	 */
1e5327b
+	if (po_join(options, mi->extra_opts) == PO_FAILED) {
1e5327b
+		errno = ENOMEM;
1e5327b
+		return 0;
1e5327b
+	}
1e5327b
+
1e5327b
+	result = nfs_sys_mount(mi, options);
1e5327b
+
1e5327b
+out_fail:
1e5327b
+	po_destroy(options);
1e5327b
+	return result;
1e5327b
+}
1e5327b
+
1e5327b
+/*
1e5327b
+ * This is a single pass through the fg/bg loop.
1e5327b
+ *
1e5327b
+ * Returns TRUE if successful, otherwise FALSE.
1e5327b
+ * "errno" is set to reflect the individual error.
1e5327b
+ */
1e5327b
+static int nfs_try_mount(struct nfsmount_info *mi)
1e5327b
+{
1e5327b
+	int result = 0;
1e5327b
+
1e5327b
+	switch (mi->version) {
1e5327b
+	case 0:
1e5327b
+		if (linux_version_code() > MAKE_VERSION(2, 6, 31)) {
1e5327b
+			errno = 0;
1e5327b
+			result = nfs_try_mount_v4(mi);
1e5327b
+			if (errno != EPROTONOSUPPORT)
1e5327b
+				break;
1e5327b
+		}
1e5327b
+	case 2:
1e5327b
+	case 3:
1e5327b
+		result = nfs_try_mount_v3v2(mi);
1e5327b
+		break;
1e5327b
+	case 4:
1e5327b
+		result = nfs_try_mount_v4(mi);
1e5327b
+		break;
1e5327b
+	default:
1e5327b
+		errno = EIO;
1e5327b
+	}
1e5327b
+
1e5327b
+	return result;
1e5327b
+}
1e5327b
+
1e5327b
+/*
1e5327b
  * Distinguish between permanent and temporary errors.
1e5327b
  *
1e5327b
  * Basically, we retry if communication with the server has