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

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