Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 130701790bf2d95e902edf16031ff596 > files > 84

autofs-5.0.1-0.rc2.164.el5_8.src.rpm

autofs-5.0.1 - fix random selection for host on different network

From: Ian Kent <raven@themaw.net>

When we select from a list of hosts from which we can mount the list
is ordered by response time within proximity.

This is intended for normal selection but when using random selection
if any hosts are on another network (and so considered further away)
they will never be at the head of the list and so are unlikely to be
used. This leads to a limited set of hosts being used for mounts which
usually isn't what's required when the random selection option is used.
---

 include/replicated.h |    2 +-
 modules/mount_nfs.c  |    2 +-
 modules/replicated.c |   34 ++++++++++++++++++++++++++++------
 3 files changed, 30 insertions(+), 8 deletions(-)


--- autofs-5.0.1.orig/include/replicated.h
+++ autofs-5.0.1/include/replicated.h
@@ -63,7 +63,7 @@ struct host {
 
 void seed_random(void);
 void free_host_list(struct host **);
-int parse_location(unsigned, struct host **, const char *);
+int parse_location(unsigned, struct host **, const char *, unsigned int);
 int prune_host_list(unsigned, struct host **, unsigned int, const char *, unsigned int);
 void dump_host_list(struct host *);
 
--- autofs-5.0.1.orig/modules/mount_nfs.c
+++ autofs-5.0.1/modules/mount_nfs.c
@@ -136,7 +136,7 @@ int mount_mount(struct autofs_point *ap,
 	else
 		vers = NFS_VERS_MASK | NFS_PROTO_MASK;
 
-	if (!parse_location(ap->logopt, &hosts, what)) {
+	if (!parse_location(ap->logopt, &hosts, what, random_selection)) {
 		info(ap->logopt, MODPREFIX "no hosts available");
 		return 1;
 	}
--- autofs-5.0.1.orig/modules/replicated.c
+++ autofs-5.0.1/modules/replicated.c
@@ -957,7 +957,8 @@ int prune_host_list(unsigned logopt, str
 	return 1;
 }
 
-static int add_host_addrs(struct host **list, const char *host, unsigned int weight)
+static int add_host_addrs(struct host **list, const char *host,
+			  unsigned int weight, unsigned int random_selection)
 {
 	struct hostent he;
 	struct hostent *phe = &he;
@@ -972,7 +973,17 @@ static int add_host_addrs(struct host **
 	if (inet_aton(host, &saddr.sin_addr)) {
 		const char *thost = (const char *) &saddr.sin_addr;
 
-		prx = get_proximity(thost, sizeof(saddr.sin_addr));
+		/*
+		 * If we are using random selection we pretend all hosts are at
+		 * the same proximity so hosts further away don't get excluded.
+		 * We can't use PROXIMITY_LOCAL or we won't perform an RPC ping
+		 * to remove hosts that may be down.
+		 */
+		if (random_selection)
+			prx = PROXIMITY_SUBNET;
+		else
+			prx = get_proximity(thost, sizeof(saddr.sin_addr));
+
 		if (prx == PROXIMITY_ERROR)
 			return 0;
 
@@ -1003,7 +1014,17 @@ static int add_host_addrs(struct host **
 	for (haddr = phe->h_addr_list; *haddr; haddr++) {
 		struct in_addr tt;
 
-		prx = get_proximity(*haddr, phe->h_length);
+		/*
+		 * If we are using random selection we pretend all hosts are at
+		 * the same proximity so hosts further away don't get excluded.
+		 * We can't use PROXIMITY_LOCAL or we won't perform an RPC ping
+		 * to remove hosts that may be down.
+		 */
+		if (random_selection)
+			prx = PROXIMITY_SUBNET;
+		else
+			prx = get_proximity(*haddr, phe->h_length);
+
 		if (prx == PROXIMITY_ERROR)
 			return 0;
 
@@ -1074,7 +1095,8 @@ static int add_local_path(struct host **
 	return 1;
 }
 
-int parse_location(unsigned logopt, struct host **hosts, const char *list)
+int parse_location(unsigned logopt, struct host **hosts,
+		   const char *list, unsigned int random_selection)
 {
 	char *str, *p, *delim;
 	unsigned int empty = 1;
@@ -1129,7 +1151,7 @@ int parse_location(unsigned logopt, stru
 				}
 
 				if (p != delim) {
-					if (!add_host_addrs(hosts, p, weight)) {
+					if (!add_host_addrs(hosts, p, weight, random_selection)) {
 						if (empty) {
 							p = next;
 							continue;
@@ -1151,7 +1173,7 @@ int parse_location(unsigned logopt, stru
 				*delim = '\0';
 				next = delim + 1;
 
-				if (!add_host_addrs(hosts, p, weight)) {
+				if (!add_host_addrs(hosts, p, weight, random_selection)) {
 					p = next;
 					continue;
 				}