Blame SOURCES/autofs-5.0.7-probe-each-nfs-version-in-turn-for-singleton-mounts.patch

304803
autofs-5.0.7 - probe each nfs version in turn for singleton mounts
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
304803
---
304803
 CHANGELOG            |    1 +
304803
 include/replicated.h |    2 ++
304803
 modules/mount_nfs.c  |   35 ++++++++++++++++++++++++++++++++++-
304803
 modules/replicated.c |    8 ++++----
304803
 4 files changed, 41 insertions(+), 5 deletions(-)
304803
304803
diff --git a/CHANGELOG b/CHANGELOG
304803
index 39d7889..48e9806 100644
304803
--- a/CHANGELOG
304803
+++ b/CHANGELOG
304803
@@ -48,6 +48,7 @@
304803
 - fix master map mount options matching.
304803
 - fix master map bogus keywork match.
304803
 - fix fix map entry duplicate offset detection.
304803
+- probe each nfs version in turn for singleton mounts.
304803
 
304803
 25/07/2012 autofs-5.0.7
304803
 =======================
304803
diff --git a/include/replicated.h b/include/replicated.h
304803
index ff0e7b9..728f131 100644
304803
--- a/include/replicated.h
304803
+++ b/include/replicated.h
304803
@@ -68,6 +68,8 @@ struct host {
304803
 };
304803
 
304803
 void seed_random(void);
304803
+struct host *new_host(const char *, struct sockaddr *, size_t,
304803
+		      unsigned int, unsigned int, unsigned int);
304803
 void free_host_list(struct host **);
304803
 int parse_location(unsigned, struct host **, const char *, unsigned int);
304803
 int prune_host_list(unsigned, struct host **, unsigned int, int);
304803
diff --git a/modules/mount_nfs.c b/modules/mount_nfs.c
304803
index 5424d74..81ba3ca 100644
304803
--- a/modules/mount_nfs.c
304803
+++ b/modules/mount_nfs.c
304803
@@ -180,9 +180,42 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
304803
 	 * We can't probe protocol rdma so leave it to mount.nfs(8)
304803
 	 * and and suffer the delay if a server isn't available.
304803
 	 */
304803
-	if (!rdma)
304803
+	if (rdma)
304803
+		goto dont_probe;
304803
+
304803
+	/*
304803
+	 * If this is a singleton mount, and NFSv4 only hasn't been asked
304803
+	 * for, and the default NFS protocol is set to v4 in the autofs
304803
+	 * configuration only probe NFSv4 and let mount.nfs(8) do fallback
304803
+	 * to NFSv3 (if it can). If the NFSv4 probe fails then probe as
304803
+	 * normal.
304803
+	 */
304803
+	if (!hosts->next &&
304803
+	    mount_default_proto == 4 &&
304803
+	    vers & NFS_VERS_MASK != 0 &&
304803
+	    vers & NFS4_VERS_MASK != 0) {
304803
+		unsigned int v4_probe_ok = 0;
304803
+		struct host *tmp = new_host(hosts->name,
304803
+					    hosts->addr, hosts->addr_len,
304803
+					    hosts->proximity,
304803
+					    hosts->weight, hosts->options);
304803
+		if (tmp) {
304803
+			tmp->rr = hosts->rr;
304803
+			prune_host_list(ap->logopt, &tmp,
304803
+					NFS4_VERS_MASK|TCP_SUPPORTED, port);
304803
+			/* If probe succeeds just try the mount with host in hosts */
304803
+			if (tmp) {
304803
+				v4_probe_ok = 1;
304803
+				free_host_list(&tmp);
304803
+			}
304803
+		}
304803
+		if (!v4_probe_ok)
304803
+			prune_host_list(ap->logopt, &hosts, vers, port);
304803
+	} else {
304803
 		prune_host_list(ap->logopt, &hosts, vers, port);
304803
+	}
304803
 
304803
+dont_probe:
304803
 	if (!hosts) {
304803
 		info(ap->logopt, MODPREFIX "no hosts available");
304803
 		return 1;
304803
diff --git a/modules/replicated.c b/modules/replicated.c
304803
index 6dbdade..0a044b9 100644
304803
--- a/modules/replicated.c
304803
+++ b/modules/replicated.c
304803
@@ -280,10 +280,10 @@ static unsigned int get_proximity(struct sockaddr *host_addr)
304803
 	return PROXIMITY_OTHER;
304803
 }
304803
 
304803
-static struct host *new_host(const char *name,
304803
-			     struct sockaddr *addr, size_t addr_len,
304803
-			     unsigned int proximity, unsigned int weight,
304803
-			     unsigned int options)
304803
+struct host *new_host(const char *name,
304803
+		      struct sockaddr *addr, size_t addr_len,
304803
+		      unsigned int proximity, unsigned int weight,
304803
+		      unsigned int options)
304803
 {
304803
 	struct host *new;
304803
 	struct sockaddr *tmp2;