public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Chuck Lever <chuck.lever@oracle.com>
To: jlayton@redhat.com
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 4/4] text-based mount: Support protocol family negotiation
Date: Fri, 22 Jan 2010 16:06:47 -0500	[thread overview]
Message-ID: <20100122210647.10598.74090.stgit@localhost.localdomain> (raw)
In-Reply-To: <20100122210221.10598.84522.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>

Jeff Layton pointed out that the current negotiation logic in
stropts.c simply doesn't handle the case where a server may have an
IPv6 address and an IPv4 address, but only NFS/IPv4 is supported.
This is typical of all currently deployed Linux servers.

Add support for trying all addresses returned from DNS when
"proto=" is not specified on the command line.
---

 utils/mount/stropts.c |   71 +++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 60 insertions(+), 11 deletions(-)

diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c
index fc1b0da..9b8c38f 100644
--- a/utils/mount/stropts.c
+++ b/utils/mount/stropts.c
@@ -576,12 +576,9 @@ static int nfs_sys_mount(struct nfsmount_info *mi, struct mount_options *opts)
 	return !result;
 }
 
-/*
- * For "-t nfs vers=2" or "-t nfs vers=3" mounts.
- */
-static int nfs_try_mount_v3v2(struct nfsmount_info *mi)
+static int nfs_do_mount_v3v2(struct nfsmount_info *mi,
+		struct sockaddr *sap, socklen_t salen)
 {
-	struct addrinfo *ai = mi->address;
 	struct mount_options *options = po_dup(mi->options);
 	int result = 0;
 
@@ -590,7 +587,7 @@ static int nfs_try_mount_v3v2(struct nfsmount_info *mi)
 		return result;
 	}
 
-	if (!nfs_append_addr_option(ai->ai_addr, ai->ai_addrlen, options)) {
+	if (!nfs_append_addr_option(sap, salen, options)) {
 		errno = EINVAL;
 		goto out_fail;
 	}
@@ -630,11 +627,36 @@ out_fail:
 }
 
 /*
- * For "-t nfs -o vers=4" or "-t nfs4" mounts.
+ * Attempt a "-t nfs vers=2" or "-t nfs vers=3" mount.
+ *
+ * Returns TRUE if successful, otherwise FALSE.
+ * "errno" is set to reflect the individual error.
  */
-static int nfs_try_mount_v4(struct nfsmount_info *mi)
+static int nfs_try_mount_v3v2(struct nfsmount_info *mi)
+{
+	struct addrinfo *ai;
+	int ret;
+
+	for (ai = mi->address; ai != NULL; ai = ai->ai_next) {
+		ret = nfs_do_mount_v3v2(mi, ai->ai_addr, ai->ai_addrlen);
+		if (ret != 0)
+			return ret;
+
+		switch (errno) {
+		case ECONNREFUSED:
+		case EOPNOTSUPP:
+		case EHOSTUNREACH:
+			continue;
+		default:
+			break;
+		}
+	}
+	return ret;
+}
+
+static int nfs_do_mount_v4(struct nfsmount_info *mi,
+		struct sockaddr *sap, socklen_t salen)
 {
-	struct addrinfo *ai = mi->address;
 	struct mount_options *options = po_dup(mi->options);
 	int result = 0;
 
@@ -662,12 +684,12 @@ static int nfs_try_mount_v4(struct nfsmount_info *mi)
 		}
 	}
 
-	if (!nfs_append_addr_option(ai->ai_addr, ai->ai_addrlen, options)) {
+	if (!nfs_append_addr_option(sap, salen, options)) {
 		errno = EINVAL;
 		goto out_fail;
 	}
 
-	if (!nfs_append_clientaddr_option(ai->ai_addr, ai->ai_addrlen, options)) {
+	if (!nfs_append_clientaddr_option(sap, salen, options)) {
 		errno = EINVAL;
 		goto out_fail;
 	}
@@ -692,6 +714,33 @@ out_fail:
 }
 
 /*
+ * Attempt a "-t nfs -o vers=4" or "-t nfs4" mount.
+ *
+ * Returns TRUE if successful, otherwise FALSE.
+ * "errno" is set to reflect the individual error.
+ */
+static int nfs_try_mount_v4(struct nfsmount_info *mi)
+{
+	struct addrinfo *ai;
+	int ret;
+
+	for (ai = mi->address; ai != NULL; ai = ai->ai_next) {
+		ret = nfs_do_mount_v4(mi, ai->ai_addr, ai->ai_addrlen);
+		if (ret != 0)
+			return ret;
+
+		switch (errno) {
+		case ECONNREFUSED:
+		case EHOSTUNREACH:
+			continue;
+		default:
+			break;
+		}
+	}
+	return ret;
+}
+
+/*
  * This is a single pass through the fg/bg loop.
  *
  * Returns TRUE if successful, otherwise FALSE.


  parent reply	other threads:[~2010-01-22 21:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-22 21:06 [RFC] [PATCH 0/4] Protocol family negotiation in mount.nfs Chuck Lever
     [not found] ` <20100122210221.10598.84522.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2010-01-22 21:06   ` [PATCH 1/4] text-based mount: Retry when server can't be reached Chuck Lever
     [not found]     ` <20100122210621.10598.15244.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2010-02-05 14:31       ` Jeff Layton
2010-01-22 21:06   ` [PATCH 2/4] text-based mount: Replace nfs_lookup() with getaddrinfo(3) Chuck Lever
2010-01-22 21:06   ` [PATCH 3/4] text-based mount: Set addr= option in nfs_try_mount_foo() Chuck Lever
2010-01-22 21:06   ` Chuck Lever [this message]
2010-02-12 18:46   ` [RFC] [PATCH 0/4] Protocol family negotiation in mount.nfs Steve Dickson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100122210647.10598.74090.stgit@localhost.localdomain \
    --to=chuck.lever@oracle.com \
    --cc=jlayton@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox