Ian Kent 239613
autofs-5.0.3 - eliminate redundant DNS name lookups
Ian Kent 239613
Ian Kent 239613
From: Ian Kent <raven@themaw.net>
Ian Kent 239613
Ian Kent 239613
When autofs tries to lookup a DNS host name where one or more DNS
Ian Kent 239613
servers aren't available the mount can take a long time. This is
Ian Kent 239613
caused by autofs doing the name lookups more often than it needs
Ian Kent 239613
to. This patch removes a number of these redundant name lookups.
Ian Kent 239613
---
Ian Kent 239613
Ian Kent 239613
 CHANGELOG            |    1 +
Ian Kent 239613
 include/replicated.h |    1 +
Ian Kent 239613
 include/rpc_subs.h   |    4 +++-
Ian Kent 239613
 lib/rpc_subs.c       |   22 ++++++++++++++++++++--
Ian Kent 239613
 modules/replicated.c |   25 +++++++++++++++++++------
Ian Kent 239613
 5 files changed, 44 insertions(+), 9 deletions(-)
Ian Kent 239613
Ian Kent 239613
Ian Kent 239613
diff --git a/CHANGELOG b/CHANGELOG
Ian Kent 239613
index 3ed84d3..995daea 100644
Ian Kent 239613
--- a/CHANGELOG
Ian Kent 239613
+++ b/CHANGELOG
Ian Kent 239613
@@ -17,6 +17,7 @@
Ian Kent 239613
 - add check for exports automatically mounted by NFS kernel client.
Ian Kent 239613
 - update nsswitch parser to ignore nsswitch sources that aren't supported.
Ian Kent 239613
 - check for map key in (possible) alternate map sources when doing lookup.
Ian Kent 239613
+- eliminate redundant DNS name lookups.
Ian Kent 239613
  
Ian Kent 239613
 14/01/2008 autofs-5.0.3
Ian Kent 239613
 -----------------------
Ian Kent 239613
diff --git a/include/replicated.h b/include/replicated.h
Ian Kent 239613
index 672f853..88cd08a 100644
Ian Kent 239613
--- a/include/replicated.h
Ian Kent 239613
+++ b/include/replicated.h
Ian Kent 239613
@@ -52,6 +52,7 @@
Ian Kent 239613
 struct host {
Ian Kent 239613
 	char *name;
Ian Kent 239613
 	char *addr;
Ian Kent 239613
+	size_t addr_len;
Ian Kent 239613
 	char *path;
Ian Kent 239613
 	unsigned int version;
Ian Kent 239613
 	unsigned int proximity;
Ian Kent 239613
diff --git a/include/rpc_subs.h b/include/rpc_subs.h
Ian Kent 239613
index 3292e01..e20a89d 100644
Ian Kent 239613
--- a/include/rpc_subs.h
Ian Kent 239613
+++ b/include/rpc_subs.h
Ian Kent 239613
@@ -46,6 +46,8 @@
Ian Kent 239613
 
Ian Kent 239613
 struct conn_info {
Ian Kent 239613
 	const char *host;
Ian Kent 239613
+	const char *addr;
Ian Kent 239613
+	size_t addr_len;
Ian Kent 239613
 	unsigned short port;
Ian Kent 239613
 	unsigned long program;
Ian Kent 239613
 	unsigned long version;
Ian Kent 239613
@@ -61,7 +63,7 @@ int rpc_udp_getclient(struct conn_info *, unsigned int, unsigned int);
Ian Kent 239613
 void rpc_destroy_udp_client(struct conn_info *);
Ian Kent 239613
 int rpc_tcp_getclient(struct conn_info *, unsigned int, unsigned int);
Ian Kent 239613
 void rpc_destroy_tcp_client(struct conn_info *);
Ian Kent 239613
-int rpc_portmap_getclient(struct conn_info *, const char *, const char *, unsigned int);
Ian Kent 239613
+int rpc_portmap_getclient(struct conn_info *, const char *, const char *, size_t, const char *, unsigned int);
Ian Kent 239613
 unsigned short rpc_portmap_getport(struct conn_info *, struct pmap *);
Ian Kent 239613
 int rpc_ping_proto(struct conn_info *);
Ian Kent 239613
 int rpc_ping(const char *, long, long, unsigned int);
Ian Kent 239613
diff --git a/lib/rpc_subs.c b/lib/rpc_subs.c
Ian Kent 239613
index 5797639..6be86c6 100644
Ian Kent 239613
--- a/lib/rpc_subs.c
Ian Kent 239613
+++ b/lib/rpc_subs.c
Ian Kent 239613
@@ -86,6 +86,11 @@ static CLIENT *create_udp_client(struct conn_info *info)
Ian Kent 239613
 	memset(&raddr, 0, sizeof(raddr));
Ian Kent 239613
 
Ian Kent 239613
 	raddr.sin_family = AF_INET;
Ian Kent 239613
+	if (info->addr) {
Ian Kent 239613
+		memcpy(&raddr.sin_addr.s_addr, info->addr, info->addr_len);
Ian Kent 239613
+		goto got_addr;
Ian Kent 239613
+	}
Ian Kent 239613
+
Ian Kent 239613
 	if (inet_aton(info->host, &raddr.sin_addr))
Ian Kent 239613
 		goto got_addr;
Ian Kent 239613
 
Ian Kent 239613
@@ -295,6 +300,11 @@ static CLIENT *create_tcp_client(struct conn_info *info)
Ian Kent 239613
 	memset(&addr, 0, sizeof(addr));
Ian Kent 239613
 
Ian Kent 239613
 	addr.sin_family = AF_INET;
Ian Kent 239613
+	if (info->addr) {
Ian Kent 239613
+		memcpy(&addr.sin_addr.s_addr, info->addr, info->addr_len);
Ian Kent 239613
+		goto got_addr;
Ian Kent 239613
+	}
Ian Kent 239613
+
Ian Kent 239613
 	if (inet_aton(info->host, &addr.sin_addr))
Ian Kent 239613
 		goto got_addr;
Ian Kent 239613
 
Ian Kent 239613
@@ -407,8 +417,8 @@ void rpc_destroy_tcp_client(struct conn_info *info)
Ian Kent 239613
 }
Ian Kent 239613
 
Ian Kent 239613
 int rpc_portmap_getclient(struct conn_info *info,
Ian Kent 239613
-			  const char *host, const char *proto,
Ian Kent 239613
-			  unsigned int option)
Ian Kent 239613
+			  const char *host, const char *addr, size_t addr_len,
Ian Kent 239613
+			  const char *proto, unsigned int option)
Ian Kent 239613
 {
Ian Kent 239613
 	struct protoent *pe_proto;
Ian Kent 239613
 	CLIENT *client;
Ian Kent 239613
@@ -418,6 +428,8 @@ int rpc_portmap_getclient(struct conn_info *info,
Ian Kent 239613
 		return 0;
Ian Kent 239613
 
Ian Kent 239613
 	info->host = host;
Ian Kent 239613
+	info->addr = addr;
Ian Kent 239613
+	info->addr_len = addr_len;
Ian Kent 239613
 	info->program = PMAPPROG;
Ian Kent 239613
 	info->port = PMAPPORT;
Ian Kent 239613
 	info->version = PMAPVERS;
Ian Kent 239613
@@ -462,6 +474,8 @@ unsigned short rpc_portmap_getport(struct conn_info *info, struct pmap *parms)
Ian Kent 239613
 		client = info->client;
Ian Kent 239613
 	else {
Ian Kent 239613
 		pmap_info.host = info->host;
Ian Kent 239613
+		pmap_info.addr = info->addr;
Ian Kent 239613
+		pmap_info.addr_len = info->addr_len;
Ian Kent 239613
 		pmap_info.port = PMAPPORT;
Ian Kent 239613
 		pmap_info.program = PMAPPROG;
Ian Kent 239613
 		pmap_info.version = PMAPVERS;
Ian Kent 239613
@@ -589,6 +603,8 @@ static unsigned int __rpc_ping(const char *host,
Ian Kent 239613
 	struct pmap parms;
Ian Kent 239613
 
Ian Kent 239613
 	info.host = host;
Ian Kent 239613
+	info.addr = NULL;
Ian Kent 239613
+	info.addr_len = 0;
Ian Kent 239613
 	info.program = NFS_PROGRAM;
Ian Kent 239613
 	info.version = version;
Ian Kent 239613
 	info.send_sz = 0;
Ian Kent 239613
@@ -769,6 +785,8 @@ exports rpc_get_exports(const char *host, long seconds, long micros, unsigned in
Ian Kent 239613
 	int status;
Ian Kent 239613
 
Ian Kent 239613
 	info.host = host;
Ian Kent 239613
+	info.addr = NULL;
Ian Kent 239613
+	info.addr_len = 0;
Ian Kent 239613
 	info.program = MOUNTPROG;
Ian Kent 239613
 	info.version = MOUNTVERS;
Ian Kent 239613
 	info.send_sz = 0;
Ian Kent 239613
diff --git a/modules/replicated.c b/modules/replicated.c
Ian Kent 239613
index 90b2925..efbe6b4 100644
Ian Kent 239613
--- a/modules/replicated.c
Ian Kent 239613
+++ b/modules/replicated.c
Ian Kent 239613
@@ -225,7 +225,9 @@ static unsigned int get_proximity(const char *host_addr, int addr_len)
Ian Kent 239613
 	return PROXIMITY_OTHER;
Ian Kent 239613
 }
Ian Kent 239613
 
Ian Kent 239613
-static struct host *new_host(const char *name, const char *addr, unsigned int proximity, unsigned int weight)
Ian Kent 239613
+static struct host *new_host(const char *name,
Ian Kent 239613
+			     const char *addr, size_t addr_len,
Ian Kent 239613
+			     unsigned int proximity, unsigned int weight)
Ian Kent 239613
 {
Ian Kent 239613
 	struct host *new;
Ian Kent 239613
 	char *tmp1, *tmp2;
Ian Kent 239613
@@ -237,11 +239,12 @@ static struct host *new_host(const char *name, const char *addr, unsigned int pr
Ian Kent 239613
 	if (!tmp1)
Ian Kent 239613
 		return NULL;
Ian Kent 239613
 
Ian Kent 239613
-	tmp2 = strdup(addr);
Ian Kent 239613
+	tmp2 = malloc(addr_len);
Ian Kent 239613
 	if (!tmp2) {
Ian Kent 239613
 		free(tmp1);
Ian Kent 239613
 		return NULL;
Ian Kent 239613
 	}
Ian Kent 239613
+	memcpy(tmp2, addr, addr_len);
Ian Kent 239613
 
Ian Kent 239613
 	new = malloc(sizeof(struct host));
Ian Kent 239613
 	if (!new) {
Ian Kent 239613
@@ -253,6 +256,7 @@ static struct host *new_host(const char *name, const char *addr, unsigned int pr
Ian Kent 239613
 	memset(new, 0, sizeof(struct host));
Ian Kent 239613
 
Ian Kent 239613
 	new->name = tmp1;
Ian Kent 239613
+	new->addr_len = addr_len;
Ian Kent 239613
 	new->addr = tmp2;
Ian Kent 239613
 	new->proximity = proximity;
Ian Kent 239613
 	new->weight = weight;
Ian Kent 239613
@@ -437,7 +441,8 @@ static unsigned int get_nfs_info(unsigned logopt, struct host *host,
Ian Kent 239613
 v3_ver:
Ian Kent 239613
 	if (!have_port_opt) {
Ian Kent 239613
 		status = rpc_portmap_getclient(pm_info,
Ian Kent 239613
-				 host->name, proto, RPC_CLOSE_DEFAULT);
Ian Kent 239613
+				host->name, host->addr, host->addr_len,
Ian Kent 239613
+				proto, RPC_CLOSE_DEFAULT);
Ian Kent 239613
 		if (!status)
Ian Kent 239613
 			goto done_ver;
Ian Kent 239613
 	}
Ian Kent 239613
@@ -551,6 +556,8 @@ static int get_vers_and_cost(unsigned logopt, struct host *host,
Ian Kent 239613
 		timeout = RPC_TIMEOUT * 8;
Ian Kent 239613
 
Ian Kent 239613
 	rpc_info.host = host->name;
Ian Kent 239613
+	rpc_info.addr = host->addr;
Ian Kent 239613
+	rpc_info.addr_len = host->addr_len;
Ian Kent 239613
 	rpc_info.program = NFS_PROGRAM;
Ian Kent 239613
 	rpc_info.timeout.tv_sec = timeout;
Ian Kent 239613
 	rpc_info.close_option = RPC_CLOSE_DEFAULT;
Ian Kent 239613
@@ -606,6 +613,8 @@ static int get_supported_ver_and_cost(unsigned logopt, struct host *host,
Ian Kent 239613
 		timeout = RPC_TIMEOUT * 8;
Ian Kent 239613
 
Ian Kent 239613
 	rpc_info.host = host->name;
Ian Kent 239613
+	rpc_info.addr = host->addr;
Ian Kent 239613
+	rpc_info.addr_len = host->addr_len;
Ian Kent 239613
 	rpc_info.program = NFS_PROGRAM;
Ian Kent 239613
 	rpc_info.timeout.tv_sec = timeout;
Ian Kent 239613
 	rpc_info.close_option = RPC_CLOSE_DEFAULT;
Ian Kent 239613
@@ -652,7 +661,8 @@ static int get_supported_ver_and_cost(unsigned logopt, struct host *host,
Ian Kent 239613
 			return 0;
Ian Kent 239613
 	} else {
Ian Kent 239613
 		int ret = rpc_portmap_getclient(&pm_info,
Ian Kent 239613
-				 host->name, proto, RPC_CLOSE_DEFAULT);
Ian Kent 239613
+				host->name, host->addr, host->addr_len,
Ian Kent 239613
+				proto, RPC_CLOSE_DEFAULT);
Ian Kent 239613
 		if (!ret)
Ian Kent 239613
 			return 0;
Ian Kent 239613
 
Ian Kent 239613
@@ -868,7 +878,7 @@ static int add_host_addrs(struct host **list, const char *host, unsigned int wei
Ian Kent 239613
 		if (prx == PROXIMITY_ERROR)
Ian Kent 239613
 			return 0;
Ian Kent 239613
 
Ian Kent 239613
-		if (!(new = new_host(host, thost, prx, weight)))
Ian Kent 239613
+		if (!(new = new_host(host, thost, sizeof(saddr.sin_addr), prx, weight)))
Ian Kent 239613
 			return 0;
Ian Kent 239613
 
Ian Kent 239613
 		if (!add_host(list, new))
Ian Kent 239613
@@ -891,11 +901,14 @@ static int add_host_addrs(struct host **list, const char *host, unsigned int wei
Ian Kent 239613
 	}
Ian Kent 239613
 
Ian Kent 239613
 	for (haddr = phe->h_addr_list; *haddr; haddr++) {
Ian Kent 239613
+		struct in_addr tt;
Ian Kent 239613
+
Ian Kent 239613
 		prx = get_proximity(*haddr, phe->h_length);
Ian Kent 239613
 		if (prx == PROXIMITY_ERROR)
Ian Kent 239613
 			return 0;
Ian Kent 239613
 
Ian Kent 239613
-		if (!(new = new_host(host, *haddr, prx, weight)))
Ian Kent 239613
+		memcpy(&tt, *haddr, sizeof(struct in_addr));
Ian Kent 239613
+		if (!(new = new_host(host, *haddr, phe->h_length, prx, weight)))
Ian Kent 239613
 			return 0;
Ian Kent 239613
 
Ian Kent 239613
 		if (!add_host(list, new)) {