Ian Kent 1cd346
autofs-5.1.1 - add configuration option to use fqdn in mounts
Ian Kent 1cd346
Ian Kent 1cd346
From: Ian Kent <raven@themaw.net>
Ian Kent 1cd346
Ian Kent 1cd346
When a server name returns multiple IP addresses autofs uses the IP
Ian Kent 1cd346
address when performing the mount to ensure that the the host proximity
Ian Kent 1cd346
order is respected, and that servers that aren't responding aren't
Ian Kent 1cd346
tried.
Ian Kent 1cd346
Ian Kent 1cd346
But sometimes people need to use the server name for the mount so
Ian Kent 1cd346
add a configuration option to enable that.
Ian Kent 1cd346
Ian Kent 1cd346
Signed-off-by: Ian Kent <raven@themaw.net>
Ian Kent 1cd346
---
Ian Kent 1cd346
 CHANGELOG                      |    1 +
Ian Kent 1cd346
 include/defaults.h             |    3 +++
Ian Kent 1cd346
 lib/defaults.c                 |   18 ++++++++++++++++++
Ian Kent 1cd346
 man/autofs.conf.5.in           |   18 ++++++++++++++++++
Ian Kent 1cd346
 modules/mount_nfs.c            |    3 ++-
Ian Kent 1cd346
 modules/replicated.c           |    6 ++++++
Ian Kent 1cd346
 redhat/autofs.conf.default.in  |    8 ++++++++
Ian Kent 1cd346
 samples/autofs.conf.default.in |    8 ++++++++
Ian Kent 1cd346
 8 files changed, 64 insertions(+), 1 deletion(-)
Ian Kent 1cd346
Ian Kent 1cd346
diff --git a/CHANGELOG b/CHANGELOG
Ian Kent 1cd346
index 2b8d224..2c516e4 100644
Ian Kent 1cd346
--- a/CHANGELOG
Ian Kent 1cd346
+++ b/CHANGELOG
Ian Kent 1cd346
@@ -19,6 +19,7 @@
Ian Kent 1cd346
 - fix update_hosts_mounts() return.
Ian Kent 1cd346
 - change lookup to use reinit instead of reopen.
Ian Kent 1cd346
 - update map_hash_table_size description.
Ian Kent 1cd346
+- add configuration option to use fqdn in mounts.
Ian Kent 1cd346
 
Ian Kent 1cd346
 21/04/2015 autofs-5.1.1
Ian Kent 1cd346
 =======================
Ian Kent 1cd346
diff --git a/include/defaults.h b/include/defaults.h
Ian Kent 1cd346
index 4f32e12..3788078 100644
Ian Kent 1cd346
--- a/include/defaults.h
Ian Kent 1cd346
+++ b/include/defaults.h
Ian Kent 1cd346
@@ -47,6 +47,8 @@
Ian Kent 1cd346
 
Ian Kent 1cd346
 #define DEFAULT_MAP_HASH_TABLE_SIZE	"1024"
Ian Kent 1cd346
 
Ian Kent 1cd346
+#define DEFAULT_USE_HOSTNAME_FOR_MOUNTS	"0"
Ian Kent 1cd346
+
Ian Kent 1cd346
 /* Config entry flags */
Ian Kent 1cd346
 #define CONF_NONE			0x00000000
Ian Kent 1cd346
 #define CONF_ENV			0x00000001
Ian Kent 1cd346
@@ -162,6 +164,7 @@ unsigned int defaults_get_mount_wait(void);
Ian Kent 1cd346
 unsigned int defaults_get_umount_wait(void);
Ian Kent 1cd346
 const char *defaults_get_auth_conf_file(void);
Ian Kent 1cd346
 unsigned int defaults_get_map_hash_table_size(void);
Ian Kent 1cd346
+unsigned int defaults_use_hostname_for_mounts(void);
Ian Kent 1cd346
 
Ian Kent 1cd346
 unsigned int conf_amd_mount_section_exists(const char *);
Ian Kent 1cd346
 char *conf_amd_get_arch(void);
Ian Kent 1cd346
diff --git a/lib/defaults.c b/lib/defaults.c
Ian Kent 1cd346
index 74fafc5..7159536 100644
Ian Kent 1cd346
--- a/lib/defaults.c
Ian Kent 1cd346
+++ b/lib/defaults.c
Ian Kent 1cd346
@@ -73,6 +73,8 @@
Ian Kent 1cd346
 
Ian Kent 1cd346
 #define NAME_MAP_HASH_TABLE_SIZE	"map_hash_table_size"
Ian Kent 1cd346
 
Ian Kent 1cd346
+#define NAME_USE_HOSTNAME_FOR_MOUNTS	"use_hostname_for_mounts"
Ian Kent 1cd346
+
Ian Kent 1cd346
 #define NAME_AMD_ARCH				"arch"
Ian Kent 1cd346
 #define NAME_AMD_AUTO_ATTRCACHE			"auto_attrcache"
Ian Kent 1cd346
 #define NAME_AMD_AUTO_DIR			"auto_dir"
Ian Kent 1cd346
@@ -335,6 +337,11 @@ static int conf_load_autofs_defaults(void)
Ian Kent 1cd346
 	if (ret == CFG_FAIL)
Ian Kent 1cd346
 		goto error;
Ian Kent 1cd346
 
Ian Kent 1cd346
+	ret = conf_update(sec, NAME_USE_HOSTNAME_FOR_MOUNTS,
Ian Kent 1cd346
+			  DEFAULT_USE_HOSTNAME_FOR_MOUNTS, CONF_ENV);
Ian Kent 1cd346
+	if (ret == CFG_FAIL)
Ian Kent 1cd346
+		goto error;
Ian Kent 1cd346
+
Ian Kent 1cd346
 	/* LDAP_URI and SEARCH_BASE can occur multiple times */
Ian Kent 1cd346
 	while ((co = conf_lookup(sec, NAME_LDAP_URI)))
Ian Kent 1cd346
 		conf_delete(co->section, co->name);
Ian Kent 1cd346
@@ -1701,6 +1708,17 @@ unsigned int defaults_get_map_hash_table_size(void)
Ian Kent 1cd346
 	return (unsigned int) size;
Ian Kent 1cd346
 }
Ian Kent 1cd346
 
Ian Kent 1cd346
+unsigned int defaults_use_hostname_for_mounts(void)
Ian Kent 1cd346
+{
Ian Kent 1cd346
+	int res;
Ian Kent 1cd346
+
Ian Kent 1cd346
+	res = conf_get_yesno(autofs_gbl_sec, NAME_USE_HOSTNAME_FOR_MOUNTS);
Ian Kent 1cd346
+	if (res < 0)
Ian Kent 1cd346
+		res = atoi(DEFAULT_USE_HOSTNAME_FOR_MOUNTS);
Ian Kent 1cd346
+
Ian Kent 1cd346
+	return res;
Ian Kent 1cd346
+}
Ian Kent 1cd346
+
Ian Kent 1cd346
 unsigned int conf_amd_mount_section_exists(const char *section)
Ian Kent 1cd346
 {
Ian Kent 1cd346
 	return conf_section_exists(section);
Ian Kent 1cd346
diff --git a/man/autofs.conf.5.in b/man/autofs.conf.5.in
Ian Kent 1cd346
index 4434eb8..6eb5d02 100644
Ian Kent 1cd346
--- a/man/autofs.conf.5.in
Ian Kent 1cd346
+++ b/man/autofs.conf.5.in
Ian Kent 1cd346
@@ -111,6 +111,24 @@ entries, in this case, is usually much less than the number of entries
Ian Kent 1cd346
 in the map. In this last case it would be unusual for the map entry
Ian Kent 1cd346
 cache to grow large enough to warrant increasing the default before
Ian Kent 1cd346
 an event that cleans stale entries, a map re-read for example.
Ian Kent 1cd346
+.TP
Ian Kent 1cd346
+.B use_hostname_for_mounts
Ian Kent 1cd346
+.br
Ian Kent 1cd346
+NFS mounts where the host name resolves to more than one IP address
Ian Kent 1cd346
+are probed for availability and to establish the order in which mounts
Ian Kent 1cd346
+to them should be tried. To ensure that mount attempts are made only
Ian Kent 1cd346
+to hosts that are responding and are tried in the order of hosts with
Ian Kent 1cd346
+the quickest response the IP address of the host needs to be used for
Ian Kent 1cd346
+the mount.
Ian Kent 1cd346
+
Ian Kent 1cd346
+If it is necessary to use the hostname given in the map entry for the
Ian Kent 1cd346
+mount regardless, then set this option to "yes".
Ian Kent 1cd346
+
Ian Kent 1cd346
+Be aware that if this is done there is no defense against the host
Ian Kent 1cd346
+name resolving to one that isn't responding and while the number
Ian Kent 1cd346
+of attempts at a successful mount will correspond to the number of
Ian Kent 1cd346
+addresses the host name resolves to the order will also not correspond
Ian Kent 1cd346
+to fastest responding hosts.
Ian Kent 1cd346
 .SS LDAP Configuration
Ian Kent 1cd346
 .P
Ian Kent 1cd346
 Configuration settings available are:
Ian Kent 1cd346
diff --git a/modules/mount_nfs.c b/modules/mount_nfs.c
Ian Kent 1cd346
index 15e1043..aa786f3 100644
Ian Kent 1cd346
--- a/modules/mount_nfs.c
Ian Kent 1cd346
+++ b/modules/mount_nfs.c
Ian Kent 1cd346
@@ -316,7 +316,8 @@ dont_probe:
Ian Kent 1cd346
 
Ian Kent 1cd346
 		/* Not a local host - do an NFS mount */
Ian Kent 1cd346
 
Ian Kent 1cd346
-		if (this->rr && this->addr) {
Ian Kent 1cd346
+		if (this->rr && this->addr &&
Ian Kent 1cd346
+		    !defaults_use_hostname_for_mounts()) {
Ian Kent 1cd346
 			socklen_t len = INET6_ADDRSTRLEN;
Ian Kent 1cd346
 			char n_buf[len + 1];
Ian Kent 1cd346
 			const char *n_addr;
Ian Kent 1cd346
diff --git a/modules/replicated.c b/modules/replicated.c
Ian Kent 1cd346
index 32860d5..8437f5f 100644
Ian Kent 1cd346
--- a/modules/replicated.c
Ian Kent 1cd346
+++ b/modules/replicated.c
Ian Kent 1cd346
@@ -667,6 +667,12 @@ int prune_host_list(unsigned logopt, struct host **list,
Ian Kent 1cd346
 	if (!*list)
Ian Kent 1cd346
 		return 0;
Ian Kent 1cd346
 
Ian Kent 1cd346
+	/* If we're using the host name then there's no point probing
Ian Kent 1cd346
+	 * avialability and respose time.
Ian Kent 1cd346
+	 */
Ian Kent 1cd346
+	if (defaults_use_hostname_for_mounts())
Ian Kent 1cd346
+		return 1;
Ian Kent 1cd346
+
Ian Kent 1cd346
 	/* Use closest hosts to choose NFS version */
Ian Kent 1cd346
 
Ian Kent 1cd346
 	first = *list;
Ian Kent 1cd346
diff --git a/redhat/autofs.conf.default.in b/redhat/autofs.conf.default.in
Ian Kent 1cd346
index da0882f..b751043 100644
Ian Kent 1cd346
--- a/redhat/autofs.conf.default.in
Ian Kent 1cd346
+++ b/redhat/autofs.conf.default.in
Ian Kent 1cd346
@@ -142,6 +142,14 @@ mount_nfs_default_protocol = 4
Ian Kent 1cd346
 #
Ian Kent 1cd346
 #map_hash_table_size = 1024
Ian Kent 1cd346
 #
Ian Kent 1cd346
+# use_hostname_for_mounts - nfs mounts where the host name resolves
Ian Kent 1cd346
+# 			 to more than one IP address normally need
Ian Kent 1cd346
+# 			 to use the IP address to esure a mount to
Ian Kent 1cd346
+# 			 a host that isn't responding isn't done.
Ian Kent 1cd346
+# 			 If that behaviour is not wanted then set
Ian Kent 1cd346
+#			 ths to "yes", default is "no".
Ian Kent 1cd346
+#
Ian Kent 1cd346
+#use_hostname_for_mounts = "no"
Ian Kent 1cd346
 #
Ian Kent 1cd346
 # Otions for the amd parser within autofs.
Ian Kent 1cd346
 #
Ian Kent 1cd346
diff --git a/samples/autofs.conf.default.in b/samples/autofs.conf.default.in
Ian Kent 1cd346
index 80abb43..4b48c63 100644
Ian Kent 1cd346
--- a/samples/autofs.conf.default.in
Ian Kent 1cd346
+++ b/samples/autofs.conf.default.in
Ian Kent 1cd346
@@ -141,6 +141,14 @@ browse_mode = no
Ian Kent 1cd346
 #
Ian Kent 1cd346
 #map_hash_table_size = 1024
Ian Kent 1cd346
 #
Ian Kent 1cd346
+# use_hostname_for_mounts - nfs mounts where the host name resolves
Ian Kent 1cd346
+# 			to more than one IP address normally need
Ian Kent 1cd346
+# 			to use the IP address to esure a mount to
Ian Kent 1cd346
+# 			a host that isn't responding isn't done.
Ian Kent 1cd346
+# 			If that behaviour is not wanted then set
Ian Kent 1cd346
+#			ths to "yes", default is "no".
Ian Kent 1cd346
+#
Ian Kent 1cd346
+#use_hostname_for_mounts = "no"
Ian Kent 1cd346
 #
Ian Kent 1cd346
 # Otions for the amd parser within autofs.
Ian Kent 1cd346
 #