Ian Kent cc4062
autofs-5.0.5 - fix master map source server unavailable handling
Ian Kent cc4062
Ian Kent cc4062
From: Ian Kent <raven@themaw.net>
Ian Kent cc4062
Ian Kent cc4062
If we get an NSS_STATUS_UNAVAIL from any server when trying to read
Ian Kent cc4062
the master map we have no choice but to not update mounted automounts
Ian Kent cc4062
because we can't know what entries may have come from the server that
Ian Kent cc4062
isn't avialable. So we leave everything the way it is and wait until
Ian Kent cc4062
the next re-read to update our mounts.
Ian Kent cc4062
---
Ian Kent cc4062
Ian Kent cc4062
 CHANGELOG             |    1 +
Ian Kent cc4062
 daemon/automount.c    |    5 +++--
Ian Kent cc4062
 daemon/lookup.c       |    9 +++++++++
Ian Kent cc4062
 include/master.h      |    1 +
Ian Kent cc4062
 lib/master.c          |    9 ++++++++-
Ian Kent cc4062
 modules/lookup_file.c |    2 --
Ian Kent cc4062
 6 files changed, 22 insertions(+), 5 deletions(-)
Ian Kent cc4062
Ian Kent cc4062
Ian Kent cc4062
--- autofs-5.0.5.orig/CHANGELOG
Ian Kent cc4062
+++ autofs-5.0.5/CHANGELOG
Ian Kent cc4062
@@ -28,6 +28,7 @@
Ian Kent cc4062
 - add locality as valid ldap master map attribute.
Ian Kent cc4062
 - add locality as valid ldap master map attribute fix.
Ian Kent cc4062
 - add simple bind authentication.
Ian Kent cc4062
+- fix master map source server unavailable handling.
Ian Kent cc4062
 
Ian Kent cc4062
 03/09/2009 autofs-5.0.5
Ian Kent cc4062
 -----------------------
Ian Kent cc4062
--- autofs-5.0.5.orig/daemon/automount.c
Ian Kent cc4062
+++ autofs-5.0.5/daemon/automount.c
Ian Kent cc4062
@@ -1478,7 +1478,6 @@ static void handle_mounts_cleanup(void *
Ian Kent cc4062
 		master_free_mapent_sources(ap->entry, 1);
Ian Kent cc4062
 		master_free_mapent(ap->entry);
Ian Kent cc4062
 	}
Ian Kent cc4062
-	master_mutex_unlock();
Ian Kent cc4062
 
Ian Kent cc4062
 	if (clean) {
Ian Kent cc4062
 		if (rmdir(path) == -1) {
Ian Kent cc4062
@@ -1497,7 +1496,9 @@ static void handle_mounts_cleanup(void *
Ian Kent cc4062
 	 */
Ian Kent cc4062
 	if (!submount)
Ian Kent cc4062
 		pthread_kill(state_mach_thid, SIGTERM);
Ian Kent cc4062
-	
Ian Kent cc4062
+
Ian Kent cc4062
+	master_mutex_unlock();
Ian Kent cc4062
+
Ian Kent cc4062
 	return;
Ian Kent cc4062
 }
Ian Kent cc4062
 
Ian Kent cc4062
--- autofs-5.0.5.orig/daemon/lookup.c
Ian Kent cc4062
+++ autofs-5.0.5/daemon/lookup.c
Ian Kent cc4062
@@ -157,6 +157,9 @@ int lookup_nss_read_master(struct master
Ian Kent cc4062
 			result = do_read_master(master, "file", age);
Ian Kent cc4062
 		}
Ian Kent cc4062
 
Ian Kent cc4062
+		if (result == NSS_STATUS_UNAVAIL)
Ian Kent cc4062
+			master->read_fail = 1;
Ian Kent cc4062
+
Ian Kent cc4062
 		return !result;
Ian Kent cc4062
 	} else {
Ian Kent cc4062
 		char *name = master->name;
Ian Kent cc4062
@@ -194,6 +197,9 @@ int lookup_nss_read_master(struct master
Ian Kent cc4062
 				result = do_read_master(master, source, age);
Ian Kent cc4062
 				master->name = name;
Ian Kent cc4062
 
Ian Kent cc4062
+				if (result == NSS_STATUS_UNAVAIL)
Ian Kent cc4062
+					master->read_fail = 1;
Ian Kent cc4062
+
Ian Kent cc4062
 				return !result;
Ian Kent cc4062
 			}
Ian Kent cc4062
 		}
Ian Kent cc4062
@@ -248,6 +254,9 @@ int lookup_nss_read_master(struct master
Ian Kent cc4062
 			continue;
Ian Kent cc4062
 		}
Ian Kent cc4062
 
Ian Kent cc4062
+		if (result == NSS_STATUS_UNAVAIL)
Ian Kent cc4062
+			master->read_fail = 1;
Ian Kent cc4062
+
Ian Kent cc4062
 		status = check_nss_result(this, result);
Ian Kent cc4062
 		if (status >= 0) {
Ian Kent cc4062
 			free_sources(&nsslist);
Ian Kent cc4062
--- autofs-5.0.5.orig/include/master.h
Ian Kent cc4062
+++ autofs-5.0.5/include/master.h
Ian Kent cc4062
@@ -56,6 +56,7 @@ struct master {
Ian Kent cc4062
 	unsigned int recurse;
Ian Kent cc4062
 	unsigned int depth;
Ian Kent cc4062
 	unsigned int reading;
Ian Kent cc4062
+	unsigned int read_fail;
Ian Kent cc4062
 	unsigned int default_ghost;
Ian Kent cc4062
 	unsigned int default_logging;
Ian Kent cc4062
 	unsigned int default_timeout;
Ian Kent cc4062
--- autofs-5.0.5.orig/lib/master.c
Ian Kent cc4062
+++ autofs-5.0.5/lib/master.c
Ian Kent cc4062
@@ -794,6 +794,7 @@ struct master *master_new(const char *na
Ian Kent cc4062
 	master->recurse = 0;
Ian Kent cc4062
 	master->depth = 0;
Ian Kent cc4062
 	master->reading = 0;
Ian Kent cc4062
+	master->read_fail = 0;
Ian Kent cc4062
 	master->default_ghost = ghost;
Ian Kent cc4062
 	master->default_timeout = timeout;
Ian Kent cc4062
 	master->default_logging = defaults_get_logging();
Ian Kent cc4062
@@ -821,7 +822,13 @@ int master_read_master(struct master *ma
Ian Kent cc4062
 	master_init_scan();
Ian Kent cc4062
 
Ian Kent cc4062
 	lookup_nss_read_master(master, age);
Ian Kent cc4062
-	master_mount_mounts(master, age, readall);
Ian Kent cc4062
+	if (!master->read_fail)
Ian Kent cc4062
+		master_mount_mounts(master, age, readall);
Ian Kent cc4062
+	else {
Ian Kent cc4062
+		master->read_fail = 0;
Ian Kent cc4062
+		if (!readall)
Ian Kent cc4062
+			master_mount_mounts(master, age, readall);
Ian Kent cc4062
+	}
Ian Kent cc4062
 
Ian Kent cc4062
 	master_mutex_lock();
Ian Kent cc4062
 
Ian Kent cc4062
--- autofs-5.0.5.orig/modules/lookup_file.c
Ian Kent cc4062
+++ autofs-5.0.5/modules/lookup_file.c
Ian Kent cc4062
@@ -656,8 +656,6 @@ int lookup_read_map(struct autofs_point 
Ian Kent cc4062
 			if (!status) {
Ian Kent cc4062
 				warn(ap->logopt,
Ian Kent cc4062
 				     "failed to read included map %s", key);
Ian Kent cc4062
-				fclose(f);
Ian Kent cc4062
-				return NSS_STATUS_UNAVAIL;
Ian Kent cc4062
 			}
Ian Kent cc4062
 		} else {
Ian Kent cc4062
 			char *s_key;