Blame SOURCES/autofs-5.1.2-include-amd-mount-section-mounts-in-master-mounts-list.patch

304803
autofs-5.1.2 - include amd mount section mounts in master mounts list
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
Currently a master map entry is required for amd format maps and
304803
top level amd mount path configuration sections can only used to
304803
provide additional per-mount configuration.
304803
304803
But being able to use the top level amd format mount path
304803
configuration sections alone allows potentially incompatible
304803
master map entries to not be included in the master map.
304803
304803
Signed-off-by: Ian Kent <raven@themaw.net>
304803
---
304803
 CHANGELOG       |    1 
304803
 README.amd-maps |   49 +++++++++++++++++++++----
304803
 lib/master.c    |  109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
304803
 3 files changed, 152 insertions(+), 7 deletions(-)
304803
304803
--- autofs-5.0.7.orig/CHANGELOG
304803
+++ autofs-5.0.7/CHANGELOG
304803
@@ -227,6 +227,7 @@
304803
 - add support for amd browsable option.
304803
 - add function conf_amd_get_map_name().
304803
 - add function conf_amd_get_mount_paths().
304803
+- include amd mount sections mounts in master mounts list.
304803
 
304803
 25/07/2012 autofs-5.0.7
304803
 =======================
304803
--- autofs-5.0.7.orig/README.amd-maps
304803
+++ autofs-5.0.7/README.amd-maps
304803
@@ -9,8 +9,10 @@ How to use amd maps in autofs
304803
 
304803
 To add amd map parsing to autofs a new "format" module has been added.
304803
 
304803
-To use this new map format module the existing master map syntax is
304803
-used as described below.
304803
+There are two ways to use this new map format module. First, the existing
304803
+master map syntax can be used as described below, and second, sections that
304803
+use the top level mount path may be added to the autofs configuration below
304803
+the "amd" section in much the same way as is done with amd.
304803
 
304803
 The master map entry syntax is:
304803
 
304803
@@ -21,8 +23,22 @@ For amd format maps this becomes:
304803
 /amd/mp   file,amd:amd.mp
304803
 
304803
 which will use file as the map source and the amd format parser for
304803
-the map. But see the section below on configuration for how to
304803
-eliminate the need to specify "map-type,format" in the master map.
304803
+the map.
304803
+
304803
+In order to use nsswitch to specify the map source an amd per-mount
304803
+section needs to be added to the autofs configuration so autofs
304803
+knows the master map entry is an amd format mount.
304803
+
304803
+If an amd-per-mount section is added to the autofs configuration a
304803
+corresponding master map entry is optional. If both are present the
304803
+map name given in the master map entry will override a "map_name"
304803
+option in the amd per-mount section.
304803
+
304803
+If an amd per-mount section is used alone then not giving the "map_type"
304803
+option will alow the use of nsswicth for map selection.
304803
+
304803
+See below for an example of an amd per-mount configuration entry.
304803
+
304803
 
304803
 Configuration sub-system changes
304803
 --------------------------------
304803
@@ -56,12 +72,19 @@ avoid the need to specify the "type,form
304803
 entry. This allows them to use the nsswitch map source functionality
304803
 in the same way autofs master map entries do.
304803
 
304803
+If amd per-mount sections are present in the autofs configuration
304803
+their corresponding master map entries are optional. This allows
304803
+amd maps to be used without adding incompatible entries to the autofs
304803
+master map in shared infrastructure environments.
304803
+
304803
 If a section for an amd mount is added below the global amd section
304803
 using the mount point path (as is done in amd.conf) then autofs will
304803
 know the map format is amd (it doesn't matter if there are no other
304803
-configuration options in the mount point section). Since the map must
304803
-be given in the master map entry the map_name option is not mandatory
304803
-as it is in amd and will no be used.
304803
+configuration options in the mount point section).
304803
+
304803
+If there is a corresponding master map entry the map given in the
304803
+master map entry will be used over the map_name option if it is
304803
+present in an amd per-mount section.
304803
 
304803
 If a mount point is present in the master map and the source of the
304803
 map is nis then it is sufficient to use (for example):
304803
@@ -86,6 +109,18 @@ or
304803
 [ /amd/mp ]
304803
 map_type = nis
304803
 
304803
+An example of an amd per-mount configuration entry is:
304803
+
304803
+[ amd ]
304803
+...
304803
+
304803
+[ /test ]
304803
+map_name = /etc/amd.test
304803
+#map_type = file
304803
+#search_path =			/etc
304803
+#browsable_dirs =		yes | no
304803
+browsable_dirs =		yes
304803
+
304803
 
304803
 amd map options that can be used
304803
 --------------------------------
304803
--- autofs-5.0.7.orig/lib/master.c
304803
+++ autofs-5.0.7/lib/master.c
304803
@@ -910,6 +910,114 @@ struct master *master_new(const char *na
304803
 	return master;
304803
 }
304803
 
304803
+static void master_add_amd_mount_section_mounts(struct master *master, time_t age)
304803
+{
304803
+	unsigned int m_logopt = master->logopt;
304803
+	struct master_mapent *entry;
304803
+	struct map_source *source;
304803
+	unsigned int loglevel;
304803
+	unsigned int logopt;
304803
+	unsigned int flags;
304803
+	char *argv[2];
304803
+	char **paths;
304803
+	int ret;
304803
+	int i;
304803
+
304803
+	loglevel = conf_amd_get_log_options();
304803
+
304803
+	paths = conf_amd_get_mount_paths();
304803
+	if (!paths)
304803
+		return;
304803
+
304803
+	i = 0;
304803
+	while (paths[i]) {
304803
+		const char *path = paths[i];
304803
+		unsigned int ghost = 0;
304803
+		char *type = NULL;
304803
+		char *map = NULL;
304803
+
304803
+		entry = master_find_mapent(master, path);
304803
+		if (entry) {
304803
+			info(m_logopt,
304803
+			     "ignoring duplicate amd section mount %s",
304803
+			     path);
304803
+			goto next;
304803
+		}
304803
+
304803
+		map = conf_amd_get_map_name(path);
304803
+		if (!map) {
304803
+			error(m_logopt,
304803
+			      "failed to get map name for amd section mount %s",
304803
+			      path);
304803
+			goto next;
304803
+		}
304803
+
304803
+		entry = master_new_mapent(master, path, age);
304803
+		if (!entry) {
304803
+			error(m_logopt,
304803
+			      "failed to allocate new amd section mount %s",
304803
+			      path);
304803
+			goto next;
304803
+		}
304803
+
304803
+		logopt = m_logopt;
304803
+		if (loglevel <= LOG_DEBUG && loglevel > LOG_INFO)
304803
+			logopt = LOGOPT_DEBUG;
304803
+		else if (loglevel <= LOG_INFO && loglevel > LOG_ERR)
304803
+			logopt = LOGOPT_VERBOSE;
304803
+
304803
+		/* It isn't possible to provide the fullybrowsable amd
304803
+		 * browsing functionality within the autofs framework.
304803
+		 * This flag will not be set if browsable_dirs = full
304803
+		 * in the configuration or fullybrowsable is present as
304803
+		 * an option.
304803
+		 */
304803
+		flags = conf_amd_get_flags(path);
304803
+		if (flags & CONF_BROWSABLE_DIRS)
304803
+			ghost = 1;
304803
+
304803
+		ret = master_add_autofs_point(entry, logopt, 0, ghost, 0);
304803
+		if (!ret) {
304803
+			error(m_logopt, "failed to add autofs_point");
304803
+			master_free_mapent(entry);
304803
+			goto next;
304803
+		}
304803
+
304803
+		type = conf_amd_get_map_type(path);
304803
+		argv[0] = map;
304803
+		argv[1] = NULL;
304803
+
304803
+		source = master_add_map_source(entry, type, "amd",
304803
+					       age, 1, (const char **) argv);
304803
+		if (!source) {
304803
+			error(m_logopt,
304803
+			      "failed to add source for amd section mount %s",
304803
+			      path);
304803
+			master_free_mapent(entry);
304803
+			goto next;
304803
+		}
304803
+
304803
+		source->exp_timeout = conf_amd_get_dismount_interval(path);
304803
+		source->master_line = 0;
304803
+
304803
+		entry->age = age;
304803
+		entry->current = NULL;
304803
+
304803
+		master_add_mapent(master, entry);
304803
+next:
304803
+		if (type)
304803
+			free(type);
304803
+		if (map)
304803
+			free(map);
304803
+		i++;
304803
+	}
304803
+
304803
+	i = 0;
304803
+	while (paths[i])
304803
+		free(paths[i++]);
304803
+	free(paths);
304803
+}
304803
+
304803
 int master_read_master(struct master *master, time_t age, int readall)
304803
 {
304803
 	unsigned int logopt = master->logopt;
304803
@@ -938,6 +1046,7 @@ int master_read_master(struct master *ma
304803
 	master_init_scan();
304803
 	lookup_nss_read_master(master, age);
304803
 	cache_unlock(nc);
304803
+	master_add_amd_mount_section_mounts(master, age);
304803
 	master_mutex_unlock();
304803
 
304803
 	if (!master->read_fail)