Blame SOURCES/autofs-5.1.6-move-readall-into-struct-master.patch

63b9c2
autofs-5.1.6 - move readall into struct master
63b9c2
63b9c2
From: Ian Kent <raven@themaw.net>
63b9c2
63b9c2
The lookup modules may need to know if the master map is being re-read
63b9c2
vis a HUP signal or is being read for the first time.
63b9c2
63b9c2
This is indicated by the readall variable so move it into the master
63b9c2
map structure so it's accessable to lookup modules.
63b9c2
63b9c2
Signed-off-by: Ian Kent <raven@themaw.net>
63b9c2
---
63b9c2
 CHANGELOG          |    1 +
63b9c2
 daemon/automount.c |   28 +++++++++++++++++-----------
63b9c2
 include/master.h   |    5 +++--
63b9c2
 lib/master.c       |   15 ++++++++-------
63b9c2
 4 files changed, 29 insertions(+), 20 deletions(-)
63b9c2
63b9c2
diff --git a/CHANGELOG b/CHANGELOG
63b9c2
index 4d83df2..4a6c042 100644
63b9c2
--- a/CHANGELOG
63b9c2
+++ b/CHANGELOG
63b9c2
@@ -103,6 +103,7 @@ xx/xx/2018 autofs-5.1.5
63b9c2
 - refactor sss getautomntent().
63b9c2
 - improve sss getautomntent() error handling.
63b9c2
 - sss introduce calculate_retry_count() function.
63b9c2
+- move readall into struct master.
63b9c2
 
63b9c2
 19/12/2017 autofs-5.1.4
63b9c2
 - fix spec file url.
63b9c2
diff --git a/daemon/automount.c b/daemon/automount.c
63b9c2
index 019bd81..9660f3f 100644
63b9c2
--- a/daemon/automount.c
63b9c2
+++ b/daemon/automount.c
63b9c2
@@ -1465,7 +1465,6 @@ static void *do_read_master(void *arg)
63b9c2
 	struct master *master;
63b9c2
 	unsigned int logopt;
63b9c2
 	time_t age;
63b9c2
-	int readall = 1;
63b9c2
 	int status;
63b9c2
 
63b9c2
 	status = pthread_mutex_lock(&mrc.mutex);
63b9c2
@@ -1496,8 +1495,11 @@ static void *do_read_master(void *arg)
63b9c2
 
63b9c2
 	info(logopt, "re-reading master map %s", master->name);
63b9c2
 
63b9c2
-	status = master_read_master(master, age, readall);
63b9c2
+	master->readall = 1;
63b9c2
 
63b9c2
+	status = master_read_master(master, age);
63b9c2
+
63b9c2
+	master->readall = 0;
63b9c2
 	master->reading = 0;
63b9c2
 
63b9c2
 	return NULL;
63b9c2
@@ -2196,7 +2198,7 @@ static void do_master_list_reset(struct master *master)
63b9c2
 	master_mutex_unlock();
63b9c2
 }
63b9c2
 
63b9c2
-static int do_master_read_master(struct master *master, int wait)
63b9c2
+static int do_master_read_master(struct master *master, time_t *age, int wait)
63b9c2
 {
63b9c2
 	sigset_t signalset;
63b9c2
 	/* Wait must be at least 1 second */
63b9c2
@@ -2204,7 +2206,6 @@ static int do_master_read_master(struct master *master, int wait)
63b9c2
 	unsigned int elapsed = 0;
63b9c2
 	int max_wait = wait;
63b9c2
 	int ret = 0;
63b9c2
-	time_t age;
63b9c2
 
63b9c2
 	sigemptyset(&signalset);
63b9c2
 	sigaddset(&signalset, SIGTERM);
63b9c2
@@ -2217,8 +2218,8 @@ static int do_master_read_master(struct master *master, int wait)
63b9c2
 
63b9c2
 		do_master_list_reset(master);
63b9c2
 
63b9c2
-		age = monotonic_time(NULL);
63b9c2
-		if (master_read_master(master, age, 0)) {
63b9c2
+		*age = monotonic_time(NULL);
63b9c2
+		if (master_read_master(master, *age)) {
63b9c2
 			ret = 1;
63b9c2
 			break;
63b9c2
 		}
63b9c2
@@ -2692,14 +2693,14 @@ int main(int argc, char *argv[])
63b9c2
 		dh_tirpc = dlopen("libtirpc.so.3", RTLD_NOW);
63b9c2
 #endif
63b9c2
 
63b9c2
-	master_read = master_read_master(master_list, age, 0);
63b9c2
+	master_read = master_read_master(master_list, age);
63b9c2
 	if (!master_read) {
63b9c2
 		/*
63b9c2
 		 * Read master map, waiting until it is available, unless
63b9c2
 		 * a signal is received, in which case exit returning an
63b9c2
 		 * error.
63b9c2
 		 */
63b9c2
-		if (!do_master_read_master(master_list, master_wait)) {
63b9c2
+		if (!do_master_read_master(master_list, &age, master_wait)) {
63b9c2
 			logmsg("%s: warning: could not read at least one "
63b9c2
 				"map source after waiting, continuing ...",
63b9c2
 				 program);
63b9c2
@@ -2707,9 +2708,14 @@ int main(int argc, char *argv[])
63b9c2
 			 * Failed to read master map, continue with what
63b9c2
 			 * we have anyway.
63b9c2
 			 */
63b9c2
-			do_master_list_reset(master_list);
63b9c2
-			age = monotonic_time(NULL);
63b9c2
-			master_read_master(master_list, age, 1);
63b9c2
+			master_mutex_lock();
63b9c2
+			master_list->readall = 1;
63b9c2
+			master_mount_mounts(master_list, age);
63b9c2
+			master_list->readall = 0;
63b9c2
+
63b9c2
+			if (list_empty(&master_list->mounts))
63b9c2
+				warn(master_list->logopt, "no mounts in table");
63b9c2
+			master_mutex_unlock();
63b9c2
 		}
63b9c2
 	}
63b9c2
 
63b9c2
diff --git a/include/master.h b/include/master.h
63b9c2
index e1d272f..f689297 100644
63b9c2
--- a/include/master.h
63b9c2
+++ b/include/master.h
63b9c2
@@ -63,6 +63,7 @@ struct master {
63b9c2
 	unsigned int depth;
63b9c2
 	unsigned int reading;
63b9c2
 	unsigned int read_fail;
63b9c2
+	unsigned int readall;
63b9c2
 	unsigned int default_ghost;
63b9c2
 	unsigned int default_logging;
63b9c2
 	unsigned int default_timeout;
63b9c2
@@ -118,11 +119,11 @@ void master_remove_mapent(struct master_mapent *);
63b9c2
 void master_free_mapent_sources(struct master_mapent *, unsigned int);
63b9c2
 void master_free_mapent(struct master_mapent *);
63b9c2
 struct master *master_new(const char *, unsigned int, unsigned int);
63b9c2
-int master_read_master(struct master *, time_t, int);
63b9c2
+int master_read_master(struct master *, time_t);
63b9c2
 int master_submount_list_empty(struct autofs_point *ap);
63b9c2
 int master_notify_submount(struct autofs_point *, const char *path, enum states);
63b9c2
 void master_notify_state_change(struct master *, int);
63b9c2
-int master_mount_mounts(struct master *, time_t, int);
63b9c2
+int master_mount_mounts(struct master *, time_t);
63b9c2
 int dump_map(struct master *, const char *, const char *);
63b9c2
 int master_show_mounts(struct master *);
63b9c2
 unsigned int master_get_logopt(void);
63b9c2
diff --git a/lib/master.c b/lib/master.c
63b9c2
index fedf807..d87d7e2 100644
63b9c2
--- a/lib/master.c
63b9c2
+++ b/lib/master.c
63b9c2
@@ -951,6 +951,7 @@ struct master *master_new(const char *name, unsigned int timeout, unsigned int f
63b9c2
 	master->depth = 0;
63b9c2
 	master->reading = 0;
63b9c2
 	master->read_fail = 0;
63b9c2
+	master->readall = 0;
63b9c2
 	master->default_ghost = flags & DAEMON_FLAGS_GHOST;
63b9c2
 	master->default_timeout = timeout;
63b9c2
 	master->default_logging = defaults_get_logging();
63b9c2
@@ -1126,7 +1127,7 @@ again:
63b9c2
 	}
63b9c2
 }
63b9c2
 
63b9c2
-int master_read_master(struct master *master, time_t age, int readall)
63b9c2
+int master_read_master(struct master *master, time_t age)
63b9c2
 {
63b9c2
 	unsigned int logopt = master->logopt;
63b9c2
 	struct mapent_cache *nc;
63b9c2
@@ -1157,15 +1158,15 @@ int master_read_master(struct master *master, time_t age, int readall)
63b9c2
 	master_add_amd_mount_section_mounts(master, age);
63b9c2
 
63b9c2
 	if (!master->read_fail)
63b9c2
-		master_mount_mounts(master, age, readall);
63b9c2
+		master_mount_mounts(master, age);
63b9c2
 	else {
63b9c2
 		master->read_fail = 0;
63b9c2
-		/* HUP signal sets readall == 1 only */
63b9c2
-		if (!readall) {
63b9c2
+		/* HUP signal sets master->readall == 1 only */
63b9c2
+		if (!master->readall) {
63b9c2
 			master_mutex_unlock();
63b9c2
 			return 0;
63b9c2
 		} else
63b9c2
-			master_mount_mounts(master, age, readall);
63b9c2
+			master_mount_mounts(master, age);
63b9c2
 	}
63b9c2
 
63b9c2
 	if (list_empty(&master->mounts))
63b9c2
@@ -1452,7 +1453,7 @@ static void check_update_map_sources(struct master_mapent *entry, int readall)
63b9c2
 	return;
63b9c2
 }
63b9c2
 
63b9c2
-int master_mount_mounts(struct master *master, time_t age, int readall)
63b9c2
+int master_mount_mounts(struct master *master, time_t age)
63b9c2
 {
63b9c2
 	struct mapent_cache *nc = master->nc;
63b9c2
 	struct list_head *p, *head;
63b9c2
@@ -1536,7 +1537,7 @@ cont:
63b9c2
 		st_mutex_unlock();
63b9c2
 
63b9c2
 		if (!ret)
63b9c2
-			check_update_map_sources(this, readall);
63b9c2
+			check_update_map_sources(this, master->readall);
63b9c2
 		else if (ret == -1 && save_errno == EBADF) {
63b9c2
 			if (!master_do_mount(this)) {
63b9c2
 				list_del_init(&this->list);