Blame SOURCES/autofs-5.1.4-use_hostname_for_mounts-shouldnt-prevent-selection-among-replicas.patch

aea863
autofs-5.1.4 - use_hostname_for_mounts shouldn't prevent selection among replicas
aea863
aea863
From: NeilBrown <neilb@suse.com>
aea863
aea863
If several replicas have been specified for a mount point,
aea863
and use_hostname_for_mount is set to "yes", the selection
aea863
between these replicas is currently disabled and the last in
aea863
the list is always chosen.
aea863
aea863
There is little point selecting between different addresses
aea863
for the one host in this case, but it is still worth
aea863
selecting between different hosts, particularly if different
aea863
weights have been specified.
aea863
aea863
This patch restores the "prune_host_list()" functionality
aea863
when use_hostname_for_mount is set, and modifies it slightly
aea863
so that only on IP address for any host:/path entry in the
aea863
config file is willl be successfully probed.  After a
aea863
success, further addresses from the same entry are skipped.
aea863
This is achieved by tracking an entry number ("ent_num") for
aea863
each 'struct host'.
aea863
aea863
Signed-off-by: NeilBrown <neilb@suse.com>
aea863
Signed-off-by: Ian Kent <raven@themaw.net>
aea863
---
aea863
 CHANGELOG            |    1 +
aea863
 include/replicated.h |    3 ++-
aea863
 modules/mount_nfs.c  |    2 +-
aea863
 modules/replicated.c |   35 ++++++++++++++++++++---------------
aea863
 4 files changed, 24 insertions(+), 17 deletions(-)
aea863
aea863
diff --git a/CHANGELOG b/CHANGELOG
aea863
index 2d5d5b1f..104fca90 100644
aea863
--- a/CHANGELOG
aea863
+++ b/CHANGELOG
aea863
@@ -9,6 +9,7 @@ xx/xx/2018 autofs-5.1.5
aea863
 - fix error return in do_nfs_mount().
aea863
 - add error handling for ext_mount_add().
aea863
 - account for recent libnsl changes.
aea863
+- use_hostname_for_mounts shouldn't prevent selection among replicas.
aea863
 
aea863
 19/12/2017 autofs-5.1.4
aea863
 - fix spec file url.
aea863
diff --git a/include/replicated.h b/include/replicated.h
aea863
index 69ab7800..0f482d21 100644
aea863
--- a/include/replicated.h
aea863
+++ b/include/replicated.h
aea863
@@ -57,6 +57,7 @@
aea863
 
aea863
 struct host {
aea863
 	char *name;
aea863
+	int ent_num;
aea863
 	struct sockaddr *addr;
aea863
 	size_t addr_len;
aea863
 	unsigned int rr;
aea863
@@ -70,7 +71,7 @@ struct host {
aea863
 };
aea863
 
aea863
 void seed_random(void);
aea863
-struct host *new_host(const char *, struct sockaddr *, size_t,
aea863
+struct host *new_host(const char *, int, struct sockaddr *, size_t,
aea863
 		      unsigned int, unsigned int, unsigned int);
aea863
 void free_host_list(struct host **);
aea863
 int parse_location(unsigned, struct host **, const char *, unsigned int);
aea863
diff --git a/modules/mount_nfs.c b/modules/mount_nfs.c
aea863
index 77166544..4cf0cd27 100644
aea863
--- a/modules/mount_nfs.c
aea863
+++ b/modules/mount_nfs.c
aea863
@@ -236,7 +236,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
aea863
 	    (vers & NFS4_VERS_MASK) != 0 &&
aea863
 	    !(vers & UDP6_REQUESTED)) {
aea863
 		unsigned int v4_probe_ok = 0;
aea863
-		struct host *tmp = new_host(hosts->name,
aea863
+		struct host *tmp = new_host(hosts->name, 0,
aea863
 					    hosts->addr, hosts->addr_len,
aea863
 					    hosts->proximity,
aea863
 					    hosts->weight, hosts->options);
aea863
diff --git a/modules/replicated.c b/modules/replicated.c
aea863
index 3ac4c70f..f7b83236 100644
aea863
--- a/modules/replicated.c
aea863
+++ b/modules/replicated.c
aea863
@@ -83,7 +83,7 @@ void seed_random(void)
aea863
 	return;
aea863
 }
aea863
 
aea863
-struct host *new_host(const char *name,
aea863
+struct host *new_host(const char *name, int ent_num,
aea863
 		      struct sockaddr *addr, size_t addr_len,
aea863
 		      unsigned int proximity, unsigned int weight,
aea863
 		      unsigned int options)
aea863
@@ -116,6 +116,7 @@ struct host *new_host(const char *name,
aea863
 	memset(new, 0, sizeof(struct host));
aea863
 
aea863
 	new->name = tmp1;
aea863
+	new->ent_num = ent_num;
aea863
 	new->addr_len = addr_len;
aea863
 	new->addr = tmp2;
aea863
 	new->proximity = proximity;
aea863
@@ -714,7 +715,7 @@ done:
aea863
 int prune_host_list(unsigned logopt, struct host **list,
aea863
 		    unsigned int vers, int port)
aea863
 {
aea863
-	struct host *this, *last, *first;
aea863
+	struct host *this, *last, *first, *prev;
aea863
 	struct host *new = NULL;
aea863
 	unsigned int proximity, selected_version = 0;
aea863
 	unsigned int v2_tcp_count, v3_tcp_count, v4_tcp_count;
aea863
@@ -726,12 +727,6 @@ int prune_host_list(unsigned logopt, struct host **list,
aea863
 	if (!*list)
aea863
 		return 0;
aea863
 
aea863
-	/* If we're using the host name then there's no point probing
aea863
-	 * avialability and respose time.
aea863
-	 */
aea863
-	if (defaults_use_hostname_for_mounts())
aea863
-		return 1;
aea863
-
aea863
 	/* Use closest hosts to choose NFS version */
aea863
 
aea863
 	first = *list;
aea863
@@ -877,11 +872,18 @@ int prune_host_list(unsigned logopt, struct host **list,
aea863
 
aea863
 	first = last;
aea863
 	this = first;
aea863
+	prev = NULL;
aea863
 	while (this) {
aea863
 		struct host *next = this->next;
aea863
 		if (!this->name) {
aea863
 			remove_host(list, this);
aea863
 			add_host(&new, this);
aea863
+		} else if (defaults_use_hostname_for_mounts() && prev &&
aea863
+			   prev->ent_num == this->ent_num) {
aea863
+			/* When we use the hostname to mount, there is no
aea863
+			 * point in probing every address it has, just one is
aea863
+			 * enough.  Skip the rest.
aea863
+			 */
aea863
 		} else {
aea863
 			status = get_supported_ver_and_cost(logopt, this,
aea863
 						selected_version, port);
aea863
@@ -889,6 +891,7 @@ int prune_host_list(unsigned logopt, struct host **list,
aea863
 				this->version = selected_version;
aea863
 				remove_host(list, this);
aea863
 				add_host(&new, this);
aea863
+				prev = this;
aea863
 			}
aea863
 		}
aea863
 		this = next;
aea863
@@ -901,7 +904,7 @@ int prune_host_list(unsigned logopt, struct host **list,
aea863
 }
aea863
 
aea863
 static int add_new_host(struct host **list,
aea863
-			const char *host, unsigned int weight,
aea863
+			const char *host, int ent_num, unsigned int weight,
aea863
 			struct addrinfo *host_addr,
aea863
 			unsigned int rr, unsigned int options)
aea863
 {
aea863
@@ -940,7 +943,7 @@ static int add_new_host(struct host **list,
aea863
 	else
aea863
 		return 0;
aea863
 
aea863
-	new = new_host(host, host_addr->ai_addr, addr_len, prx, weight, options);
aea863
+	new = new_host(host, ent_num, host_addr->ai_addr, addr_len, prx, weight, options);
aea863
 	if (!new)
aea863
 		return 0;
aea863
 
aea863
@@ -953,7 +956,7 @@ static int add_new_host(struct host **list,
aea863
 	return 1;
aea863
 }
aea863
 
aea863
-static int add_host_addrs(struct host **list, const char *host,
aea863
+static int add_host_addrs(struct host **list, const char *host, int ent_num,
aea863
 			  unsigned int weight, unsigned int options)
aea863
 {
aea863
 	struct addrinfo hints, *ni, *this;
aea863
@@ -988,7 +991,7 @@ static int add_host_addrs(struct host **list, const char *host,
aea863
 
aea863
 	this = ni;
aea863
 	while (this) {
aea863
-		ret = add_new_host(list, host, weight, this, 0, options);
aea863
+		ret = add_new_host(list, host, ent_num, weight, this, 0, options);
aea863
 		if (!ret)
aea863
 			break;
aea863
 		this = this->ai_next;
aea863
@@ -1027,7 +1030,7 @@ try_name:
aea863
 		rr++;
aea863
 	this = ni;
aea863
 	while (this) {
aea863
-		ret = add_new_host(list, host, weight, this, rr, options);
aea863
+		ret = add_new_host(list, host, ent_num, weight, this, rr, options);
aea863
 		if (!ret)
aea863
 			break;
aea863
 		this = this->ai_next;
aea863
@@ -1120,6 +1123,7 @@ int parse_location(unsigned logopt, struct host **hosts,
aea863
 {
aea863
 	char *str, *p, *delim;
aea863
 	unsigned int empty = 1;
aea863
+	int ent_num = 1;
aea863
 
aea863
 	if (!list)
aea863
 		return 0;
aea863
@@ -1177,7 +1181,7 @@ int parse_location(unsigned logopt, struct host **hosts,
aea863
 				}
aea863
 
aea863
 				if (p != delim) {
aea863
-					if (!add_host_addrs(hosts, p, weight, options)) {
aea863
+					if (!add_host_addrs(hosts, p, ent_num, weight, options)) {
aea863
 						if (empty) {
aea863
 							p = next;
aea863
 							continue;
aea863
@@ -1199,7 +1203,7 @@ int parse_location(unsigned logopt, struct host **hosts,
aea863
 				*delim = '\0';
aea863
 				next = delim + 1;
aea863
 
aea863
-				if (!add_host_addrs(hosts, p, weight, options)) {
aea863
+				if (!add_host_addrs(hosts, p, ent_num, weight, options)) {
aea863
 					p = next;
aea863
 					continue;
aea863
 				}
aea863
@@ -1213,6 +1217,7 @@ int parse_location(unsigned logopt, struct host **hosts,
aea863
 			return 0;
aea863
 		}
aea863
 
aea863
+		ent_num++;
aea863
 		p = next;
aea863
 	}
aea863